* Paddy Carter, Nicolas Van de Sijpe, and Raphael Calel, 13-June-2020
* Create tables with results


clear all
set more off
/* Set path to correct folder */ 
local DISK Nicolas // options: Nicolas, Paddy
if "`DISK'"=="Paddy" {
	cd "C:\Users\Paddy Carter\Dropbox\Development Finance Institutions\Country\Monte Carlo"
}
else if "`DISK'"=="Nicolas" {
	cd "C:\Users\ec1nv\Dropbox\My Documents\My Papers\Development Finance Institutions\Country\Monte Carlo"
	local tablesexport "C:\Users\ec1nv\Dropbox\My Documents\My Papers\Development Finance Institutions\Paper\Tables"
}
else {
	di as error "Incorrect content for local DISK"
	exit
}
set matsize 500


*************************************************************************
* OLS and FE
*************************************************************************
foreach option in exclhighdb "" { // exclhighdb drops replications where DFI sector budget exceeds # projects with er > 2 in at least one year.
	foreach num of numlist 1/14 {
		clear
		capture log close
		log using "./Generated data/OLSFE`num'", replace text
		use "./Generated data/OLSFE`num'.dta"

		if "`option'" == "exclhighdb" {
			drop if maxdbpercnumprojerover2 >= 1 & maxdbpercnumprojerover2 != .
		}
		else if "`option'" == "" {
			// do nothing
		}
		else {
			di as error "Local option not specified correctly"
		}


		/* First check if all replications have been successful. */
		egen nummissing = rowmiss(olsbetadfi-maxdbpercnumprojerover2)
		tab nummissing, missing
		count if nummissing == 0
		scalar successfulreps = r(N)
		foreach var of varlist * { 
			replace `var' = . if nummissing != 0
		}


		/* Selected statistics to export to Excel later: */
		/* OLS without pc */
		su olsbetadfi, detail
		scalar olsbetadfimean = r(mean)
		local olsbetadfimean`num': di %4.2f olsbetadfimean
		scalar olsbetadfisd = r(sd)
		local olsbetadfisd`num': di %4.2f olsbetadfisd
		//
		count if olspzeroadd < 0.05
		scalar olszeroaddpercreject = (r(N)/successfulreps)*100
		local olszeroaddpercreject`num': di %5.0g olszeroaddpercreject
		count if olspfulladd < 0.05
		scalar olsfulladdpercreject = (r(N)/successfulreps)*100
		local olsfulladdpercreject`num': di %5.0g olsfulladdpercreject
		//
		su olsr2
		scalar olsr2mean = r(mean)
		/* OLS with pc */
		su olspcbetadfi, detail
		scalar olspcbetadfimean = r(mean)
		local olspcbetadfimean`num': di %4.2f olspcbetadfimean
		scalar olspcbetadfisd = r(sd)
		local olspcbetadfisd`num': di %4.2f olspcbetadfisd
		//
		count if olspcpzeroadd < 0.05
		scalar olspczeroaddpercreject = (r(N)/successfulreps)*100	
		local olspczeroaddpercreject`num': di %5.0g olspczeroaddpercreject
		count if olspcpfulladd < 0.05
		scalar olspcfulladdpercreject = (r(N)/successfulreps)*100
		local olspcfulladdpercreject`num': di %5.0g olspcfulladdpercreject
		//
		su olspcr2
		scalar olspcr2mean = r(mean)
		su olspcnodfir2
		scalar olspcnodfir2mean = r(mean)
		su olspcnodfinotdummiesr2
		scalar olspcnodfinotdummiesr2mean = r(mean)

		/* FE */
		su febetadfi, detail
		scalar febetadfimean = r(mean)
		local febetadfimean`num': di %4.2f febetadfimean
		scalar febetadfisd = r(sd)
		local febetadfisd`num': di %4.2f febetadfisd
		//
		count if fepzeroadd < 0.05
		scalar fezeroaddpercreject=(r(N)/successfulreps)*100
		local fezeroaddpercreject`num': di %5.0g fezeroaddpercreject
		count if fepfulladd < 0.05
		scalar fefulladdpercreject=(r(N)/successfulreps)*100
		local fefulladdpercreject`num': di %5.0g fefulladdpercreject
		//
		su fewr2
		scalar fewr2mean = r(mean)
		/* FE with pc */
		su fepcbetadfi, detail
		scalar fepcbetadfimean = r(mean)
		local fepcbetadfimean`num': di %4.2f fepcbetadfimean
		scalar fepcbetadfisd = r(sd)
		local fepcbetadfisd`num': di %4.2f fepcbetadfisd
		//
		count if fepcpzeroadd < 0.05
		scalar fepczeroaddpercreject=(r(N)/successfulreps)*100
		local fepczeroaddpercreject`num': di %5.0g fepczeroaddpercreject
		count if fepcpfulladd < 0.05
		scalar fepcfulladdpercreject=(r(N)/successfulreps)*100
		local fepcfulladdpercreject`num': di %5.0g fepcfulladdpercreject
		//
		su fepcwr2
		scalar fepcwr2mean = r(mean)
		su fepcnodfiwr2
		scalar fepcnodfiwr2mean = r(mean)
		su fepcnodfinotdummieswr2
		scalar fepcnodfinotdummieswr2mean = r(mean)
		
		/* Omitted variable bias in OLS: */
		/* Coefficient when controlling for number of projects with return over 2. */
		su olsbetadfitrue
		scalar olsbetadfitruemean = r(mean)
		// with pc included
		su olspcbetadfitrue
		scalar olspcbetadfitruemean = r(mean)
		/* Omitted variable bias */ 
		gen double OVB = olsbetanumprojerover2*olsdelta
		su OVB
		scalar olsbiasdfimean = r(mean)
		su olsbetanumprojerover2
		scalar olsbetanumprojerover2mean = r(mean)
		su olsdelta
		scalar olsdeltamean = r(mean)
		su olsdeltapartialledout
		scalar olsdeltapartoutmean = r(mean)
		su olsdeltadenom
		scalar olsdeltadenommean = r(mean)
		su olsdeltanum
		scalar olsdeltanummean = r(mean)
		gen double olsdeltapartoutman = olsdeltanum/olsdeltadenom
		su olsdeltapartoutman
		scalar olsdeltapartoutmanmean = r(mean)
		su covnumprojver2DFIinv
		scalar covnumprojver2DFIinvmean = r(mean)
		su varDFIinv
		scalar varDFIinvmean = r(mean)
		//
		gen double OVBpc = olspcbetanumprojerover2*olspcdelta
		su OVBpc
		scalar olspcbiasdfimean = r(mean)
		su olspcbetanumprojerover2
		scalar olspcbetanumprojerover2mean = r(mean)
		su olspcdelta
		scalar olspcdeltamean = r(mean)
		su olspcbetapctrue
		scalar olspcbetapctruemean = r(mean)
		su olspcdeltapartialledout
		scalar olspcdeltapartoutmean = r(mean)
		su olspcdeltadenom
		scalar olspcdeltadenommean = r(mean)
		su olspcdeltanum
		scalar olspcdeltanummean = r(mean)
		gen double olspcdeltapartoutman = olspcdeltanum/olspcdeltadenom
		su olspcdeltapartoutman
		scalar olspcdeltapartoutmanmean = r(mean)
		
		count if maxdbpercnumprojerover2 >= 1 & maxdbpercnumprojerover2 != .
		scalar countmaxdbpercnumprojerover2exc1 = r(N)
		
		su medinvDFIvsprivate, detail
		scalar medmedinvDFIvsprivate = r(p50)

		scalar empty = .
		scalar number = `num'

		
		// Put statistics in matrix:
		matrix OLSFE_`num' = (number \ olsbetadfimean \ olsbetadfitruemean \ olsbiasdfimean \ olsbetanumprojerover2mean \ olsdeltamean \ olsdeltapartoutmean \ olsdeltapartoutmanmean ///
		\ olsdeltanummean \ olsdeltadenommean \ covnumprojver2DFIinvmean \ varDFIinvmean ///
		\ olsbetadfisd  \ olszeroaddpercreject \ olsfulladdpercreject \ olsr2mean /// 
		\ olspcbetadfimean  \ olspcbetadfitruemean \ olspcbiasdfimean \ olspcbetanumprojerover2mean \ olspcdeltamean \ olspcdeltapartoutmean \ olspcdeltapartoutmanmean /// 
		\ olspcdeltanummean \ olspcdeltadenommean ///
		\ olspcbetapctruemean \ olspcbetadfisd \ olspczeroaddpercreject \ olspcfulladdpercreject \ olspcr2mean ///
		\ olspcnodfir2mean \ olspcnodfinotdummiesr2mean \ empty /// 
		\ febetadfimean \ febetadfisd \ fezeroaddpercreject \ fefulladdpercreject \ fewr2mean /// 
		\ fepcbetadfimean \ fepcbetadfisd \ fepczeroaddpercreject \ fepcfulladdpercreject \ fepcwr2mean \ fepcnodfiwr2mean \ fepcnodfinotdummieswr2mean /// 
		\ empty \ countmaxdbpercnumprojerover2exc1 \ successfulreps \ medmedinvDFIvsprivate)
		matrix list OLSFE_`num'

		log close
	}


	/* Construct matrices that combine results. */
	/* First table: */
	foreach num of numlist 1/14 {
		if `num'==1 { 
			matrix tableOLSFE = OLSFE_`num'
		}
		else { 
			matrix tableOLSFE=(tableOLSFE, OLSFE_`num')
		}        
	}


	/* Export to Excel. */
	putexcel set "./Tables/OLSFEtable_`option'", replace
	putexcel B2 = matrix(tableOLSFE) // starting point of table
	//
	local row 3
	putexcel A`row++' = "OLS DFI coeff. mean"
	putexcel A`row++' = "OLS DFI coeff. mean in true model"
	putexcel A`row++' = "OLS DFI mean bias manually calculated"
	putexcel A`row++' = "OLS # projects er > 2 coeff. mean"
	putexcel A`row++' = "Delta coeff. mean"
	putexcel A`row++' = "Delta coeff. mean partialled out"
	putexcel A`row++' = "Delta coeff. mean partialled out, manually calculated"
	putexcel A`row++' = "Delta coeff. numerator mean"
	putexcel A`row++' = "Delta coeff. denominator mean"
	putexcel A`row++' = "Raw cov. # projects er > 2 and DFI investment mean"
	putexcel A`row++' = "Raw var. DFI investment mean"
	putexcel A`row++' = "OLS DFI coeff. st. dev."
	putexcel A`row++' = "OLS % reject zero additionality"
	putexcel A`row++' = "OLS % reject full additionality"
	putexcel A`row++' = "OLS R2 mean"
	//
	putexcel A`row++' = "OLS with pc DFI coeff. mean"
	putexcel A`row++' = "OLS with pc DFI coeff. mean in true model"
	putexcel A`row++' = "OLS with pc DFI mean bias manually calculated"
	putexcel A`row++' = "OLS with pc # projects er > 2 coeff. mean"
	putexcel A`row++' = "Delta coeff. mean with pc"
	putexcel A`row++' = "Delta coeff. mean partialled out with pc"
	putexcel A`row++' = "Delta coeff. mean partialled out, manually calculated, with pc"
	putexcel A`row++' = "Delta coeff. with pc numerator mean"
	putexcel A`row++' = "Delta coeff. with pc denominator mean"
	putexcel A`row++' = "OLS pc coeff. mean in true model"
	putexcel A`row++' = "OLS with pc DFI coeff. st. dev."
	putexcel A`row++' = "OLS with pc % reject zero additionality"
	putexcel A`row++' = "OLS with pc % reject full additionality"
	putexcel A`row++' = "OLS with pc R2 mean"
	putexcel A`row++' = "OLS with pc no DFI R2 mean"
	putexcel A`row++' = "OLS with pc no DFI and no time dummies R2 mean"
	//
	putexcel A`row++' = ""
	//
	putexcel A`row++' = "FE DFI coeff. mean"
	putexcel A`row++' = "FE DFI coeff. st. dev."
	putexcel A`row++' = "FE % reject zero additionality"
	putexcel A`row++' = "FE % reject full additionality"
	putexcel A`row++' = "FE within R2 mean"
	//
	putexcel A`row++' = "FE with pc DFI coeff. mean"
	putexcel A`row++' = "FE with pc DFI coeff. st. dev."
	putexcel A`row++' = "FE with pc % reject zero additionality"
	putexcel A`row++' = "FE with pc % reject full additionality"
	putexcel A`row++' = "FE with pc within R2 mean"
	putexcel A`row++' = "FE with pc no DFI within R2 mean"
	putexcel A`row++' = "FE with pc no DFI and no time dummies within R2 mean"
	//
	putexcel A`row++' = ""
	putexcel A`row++' = "Number of datasets where max db exceeds # proj. with er > 2"
	putexcel A`row++' = "# successful replications"
	putexcel A`row++' = "Med. of med. DFI inv/private"
	//	
	putexcel B1= "Zero add., random, no pc noise"
	putexcel C1= "Zero add., random, noise = 0.5"
	putexcel D1= "Zero add., random, noise = 1"
	putexcel E1= "Zero add., pclow, no pc noise"
	putexcel F1= "Zero add., pclow, noise = 0.5"
	putexcel G1= "Zero add., pclow, noise = 1"
	putexcel H1= "Full add., random, no pc noise"
	putexcel I1= "Full add., random, noise = 0.5"
	putexcel J1= "Full add., random, noise = 1"
	putexcel K1= "Full add., pclow, no pc noise"
	putexcel L1= "Full add., pclow, noise = 0.5"
	putexcel M1= "Full add., pclow, noise = 1"
	putexcel N1= "Full add., random, noise = 0.5, btot = 3"
	putexcel O1= "Full add., pclow, noise = 0.5, btot = 3"


	/* Now generate table to export to TeX, using texdoc. */
	/* Random selection */
	texdoc init "`tablesexport'/OLSFEexport_random_`option'.tex", replace force
	tex  									 & \mcolsfe{(1)} 				 & \mcolsfe{(2)} 				   & \mcolsfe{(3)} 						   & \mcolsfe{(4)} 					 & \mcolsfe{(5)} 				 & \mcolsfe{(6)} 				   & \mcolsfe{(7)} 						   & \mcolsfe{(8)} \\
	tex $\beta$                              & \mcolsfe{0}                   & \mcolsfe{0}                     & \mcolsfe{0}                           & \mcolsfe{0}                     & \mcolsfe{1}                   & \mcolsfe{1}                     & \mcolsfe{1}                           & \mcolsfe{1} \\
	tex $\mathit{pc}$                        & \mcolsfe{excl.}               & \mcolsfe{$\sigma_m^{2} = 1$}    & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}} & \mcolsfe{$\sigma_m^{2} = 0$}    & \mcolsfe{excl.}               & \mcolsfe{$\sigma_m^{2} = 1$}    & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}} & \mcolsfe{$\sigma_m^{2} = 0$} \\
	tex \cmidrule{1-9}
	tex Mean $\widehat{\beta}_{OLS}$	     & `olsbetadfimean1'             & `olspcbetadfimean3'             & `olspcbetadfimean2'                   & `olspcbetadfimean1'             & `olsbetadfimean7'             & `olspcbetadfimean9'             & `olspcbetadfimean8'                   & `olspcbetadfimean7'           \\
	tex Std.\ dev.\	                         & `olsbetadfisd1'               & `olspcbetadfisd3'               & `olspcbetadfisd2'                     & `olspcbetadfisd1'               & `olsbetadfisd7'               & `olspcbetadfisd9'               & `olspcbetadfisd8'                     & `olspcbetadfisd7'               \\
//	tex \mbox{\% reject $\beta \leqslant 0$} & \mcc{`olszeroaddpercreject1'} & \mcc{`olspczeroaddpercreject3'} & \mcc{`olspczeroaddpercreject2'}       & \mcc{`olspczeroaddpercreject1'} &                               &                                 &                                       &                                 \\
//	tex \mbox{\% reject $\beta \geqslant 1$} &                               &                                 &                                       &                                 & \mcc{`olsfulladdpercreject7'} & \mcc{`olspcfulladdpercreject9'} & \mcc{`olspcfulladdpercreject8'}       & \mcc{`olspcfulladdpercreject7'}  \\
	tex Mean $\widehat{\beta}_{FE}$	         & `febetadfimean1'              & `fepcbetadfimean3'              & `fepcbetadfimean2'                    & `fepcbetadfimean1'              & `febetadfimean7'              & `fepcbetadfimean9'              & `fepcbetadfimean8'                    & `fepcbetadfimean7'           \\
	tex Std.\ dev.\	                         & `febetadfisd1'                & `fepcbetadfisd3'                & `fepcbetadfisd2'                      & `fepcbetadfisd1'                & `febetadfisd7'                & `fepcbetadfisd9'                & `fepcbetadfisd8'                      & `fepcbetadfisd7'              \\
//	tex \mbox{\% reject $\beta \leqslant 0$} & \mcc{`fezeroaddpercreject1'}  & \mcc{`fepczeroaddpercreject3'}  & \mcc{`fepczeroaddpercreject2'}        & \mcc{`fepczeroaddpercreject1'}  &                               &                                 &                                       &                                 \\
//	tex \mbox{\% reject $\beta \geqslant 1$} &                               &                                 &                                       &                                 & \mcc{`fefulladdpercreject7'}  & \mcc{`fepcfulladdpercreject9'}  & \mcc{`fepcfulladdpercreject8'}        & \mcc{`fepcfulladdpercreject7'}   \\
	tex \bottomrule
	texdoc close


	/* pclow selection */
	texdoc init "`tablesexport'/OLSFEexport_pclow_`option'.tex", replace force
	tex  									 & \mcolsfe{(1)} 				 & \mcolsfe{(2)} 				   & \mcolsfe{(3)} 						   & \mcolsfe{(4)} 					 & \mcolsfe{(5)} 				 & \mcolsfe{(6)} 				   & \mcolsfe{(7)} 						   & \mcolsfe{(8)} \\
	tex $\beta$                              & \mcolsfe{0}                   & \mcolsfe{0}                     & \mcolsfe{0}                           & \mcolsfe{0}                     & \mcolsfe{1}                   & \mcolsfe{1}                     & \mcolsfe{1}                           & \mcolsfe{1} \\
	tex $\mathit{pc}$                        & \mcolsfe{excl.}               & \mcolsfe{$\sigma_m^{2} = 1$}    & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}} & \mcolsfe{$\sigma_m^{2} = 0$}    & \mcolsfe{excl.}               & \mcolsfe{$\sigma_m^{2} = 1$}    & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}} & \mcolsfe{$\sigma_m^{2} = 0$} \\
	tex \cmidrule{1-9}
	tex Mean $\widehat{\beta}_{OLS}$	     & `olsbetadfimean4'             & `olspcbetadfimean6'             & `olspcbetadfimean5'                   & `olspcbetadfimean4'             & `olsbetadfimean10'             & `olspcbetadfimean12'             & `olspcbetadfimean11'                   & `olspcbetadfimean10'           \\
	tex Std.\ dev.\	                         & `olsbetadfisd4'               & `olspcbetadfisd6'               & `olspcbetadfisd5'                     & `olspcbetadfisd4'               & `olsbetadfisd10'               & `olspcbetadfisd12'               & `olspcbetadfisd11'                     & `olspcbetadfisd10'               \\
	tex \mbox{\% reject $\beta \leqslant 0$} & \mcc{`olszeroaddpercreject4'} & \mcc{`olspczeroaddpercreject6'} & \mcc{`olspczeroaddpercreject5'}       & \mcc{`olspczeroaddpercreject4'} &                               &                                 &                                       &                                 \\
	tex \mbox{\% reject $\beta \geqslant 1$} &                               &                                 &                                       &                                 & \mcc{`olsfulladdpercreject10'} & \mcc{`olspcfulladdpercreject12'} & \mcc{`olspcfulladdpercreject11'}       & \mcc{`olspcfulladdpercreject10'}  \\
	tex Mean $\widehat{\beta}_{FE}$	         & `febetadfimean4'              & `fepcbetadfimean6'              & `fepcbetadfimean5'                    & `fepcbetadfimean4'              & `febetadfimean10'              & `fepcbetadfimean12'              & `fepcbetadfimean11'                    & `fepcbetadfimean10'           \\
	tex Std.\ dev.\	                         & `febetadfisd4'                & `fepcbetadfisd6'                & `fepcbetadfisd5'                      & `fepcbetadfisd4'                & `febetadfisd10'                & `fepcbetadfisd12'                & `fepcbetadfisd11'                      & `fepcbetadfisd10'              \\
	tex \mbox{\% reject $\beta \leqslant 0$} & \mcc{`fezeroaddpercreject4'}  & \mcc{`fepczeroaddpercreject6'}  & \mcc{`fepczeroaddpercreject5'}        & \mcc{`fepczeroaddpercreject4'}  &                               &                                 &                                       &                                 \\
	tex \mbox{\% reject $\beta \geqslant 1$} &                               &                                 &                                       &                                 & \mcc{`fefulladdpercreject10'}  & \mcc{`fepcfulladdpercreject12'}  & \mcc{`fepcfulladdpercreject11'}        & \mcc{`fepcfulladdpercreject10'}   \\
	tex \bottomrule
	texdoc close


} // end loop over exclhighdb or not


*************************************************************************
* GMM WITH ZERO ADDITIONALITY
*************************************************************************
foreach option in exclhighdb "" { // exclhighdb drops replications where DFI sector budget exceeds # projects with er > 2 in at least one year.
	foreach num of numlist 1/9 { // start loop over generated datasets/experiments
		clear
		capture log close
		log using "./Generated data/GMMzeroadd`num'", replace text
		use "./Generated data/GMMzeroadd`num'.dta"

		
		if "`option'" == "exclhighdb" {
			drop if maxdbpercnumprojerover2 >= 1 & maxdbpercnumprojerover2 != .
		}
		else if "`option'" == "" {
			// do nothing
		}
		else {
			di as error "Local option not specified correctly"
		}


		/* First check if all replications have been successful. */
		egen nummissing = rowmiss(betadfi1-finalnumprojerover2)
		tab nummissing, missing
		count if nummissing == 0
		scalar successfulreps = r(N)
		foreach var of varlist * { 
			replace `var' = . if nummissing != 0
		}

		
		/* Selected statistics to export to Excel later: */
		foreach model of numlist 1/8 { // start loop over models estimated within each dataset

			foreach wpc in "" "wpc" { // loop over statistics without and with control for pc

				/* Results */
				su betadfi`wpc'`model', detail
				scalar DFIinv`wpc'`model'mean = r(mean)
				scalar DFIinv`wpc'`model'med = r(p50)
				local sysGMM`wpc'`model'betadfimedian`num': di %4.2f DFIinv`wpc'`model'med				
				scalar DFIinv`wpc'`model'sd = r(sd)
				local sysGMM`wpc'`model'betadfisd`num': di %4.2f DFIinv`wpc'`model'sd							
				//
				count if pzeroadd`wpc'`model' < 0.05
				scalar pzeroaddpercreject`wpc'`model' = (r(N)/successfulreps)*100
				local sysGMMzeroaddpercreject`wpc'`model'`num': di %5.0g pzeroaddpercreject`wpc'`model'
				//
				count if pfulladd`wpc'`model' < 0.05
				scalar pfulladdpercreject`wpc'`model' = (r(N)/successfulreps)*100
				//
				capture noisily su betalagdep`wpc'`model', detail
				scalar lagdep`wpc'`model'mean = r(mean)
				scalar lagdep`wpc'`model'med = r(p50)
				scalar lagdep`wpc'`model'sd = r(sd)
				
				/* Diagnostic checks */
				capture noisily su numinstr`wpc'`model'
				scalar numinstr`wpc'`model' = r(mean)
				// Calculate percentage of diagnostic tests that "pass" (i.e. don't suggest a problem, at a 10% significance level)
				capture noisily count if m1`wpc'`model' < 0 & m1p`wpc'`model' < 0.1 
				scalar m1percpass`wpc'`model' = (r(N)/successfulreps)*100
				if _rc == 111 {
					scalar m1percpass`wpc'`model' = .			
				}			
				
				capture noisily count if m2p`wpc'`model' > 0.1 & m2p`wpc'`model' != .
				scalar m2percpass`wpc'`model' = (r(N)/successfulreps)*100
				if _rc == 111 {
					scalar m2percpass`wpc'`model' = .			
				}
				
				capture noisily count if hansp`wpc'`model' > 0.1 & hansp`wpc'`model' != .
				scalar hansenpercpass`wpc'`model' = (r(N)/successfulreps)*100
				if _rc == 111 {
					scalar hansenpercpass`wpc'`model' = .			
				}
				local sysGMMhansenpercpass`wpc'`model'`num': di %5.0g hansenpercpass`wpc'`model'
				
				capture noisily count if sargp`wpc'`model' > 0.1 & sargp`wpc'`model' != .
				scalar sarganpercpass`wpc'`model' = (r(N)/successfulreps)*100
				if _rc == 111 {
					scalar sarganpercpass`wpc'`model' = .			
				}
				
				foreach moment in lev lagdep DFIinvdiff DFIinvlev { // pc moment condition follows later, outside of wpc loop
					capture noisily count if diffHp_`moment'`wpc'`model' > 0.1 & diffHp_`moment'`wpc'`model' != .
					scalar hansenpercpass`moment'`wpc'`model' = (r(N)/successfulreps)*100
					if _rc == 111 {
						scalar hansenpercpass`moment'`wpc'`model' = .			
					}
				}
				
				capture noisily su condFDFI`wpc'`model', detail
				scalar condFDFI`wpc'`model'med = r(p50)
				local sysGMMcondFDFI`wpc'`model'med`num': di %5.0g condFDFI`wpc'`model'med
							
				capture noisily count if condFDFIp`wpc'`model' < 0.05
				scalar condFDFIpercrejunderid`wpc'`model' = (r(N)/successfulreps)*100
				if _rc == 111 {
					scalar condFDFIpercrejunderid`wpc'`model' = .			
				}
				local sysGMMcondFDFIpercrej`wpc'`model'`num': di %5.0g condFDFIpercrejunderid`wpc'`model'
				
			} // close loop over statistics without and with control for pc 
			
			/* Statistic that only exists in the model with pc */
			capture noisily count if diffHp_pc`model' > 0.1 & diffHp_pc`model' != .
			scalar hansenpercpasspc`model' = (r(N)/successfulreps)*100
			if _rc == 111 {
				scalar hansenpercpasspc`model' = .			
			}

		} // close loop over models estimated within each dataset

		
		/* IV estimation (first the statistics that show up in 6, 8) */
		foreach model of numlist 6 8 { // start loop over models 6 8
			foreach wpc in "" "wpc" { // loop over statistics without and with control for pc
				capture noisily su FSrobustF`wpc'`model', detail
				scalar FSrobF`wpc'`model'med = r(p50)
			} // close loop over statistics without and with control for pc 
			// some statistics only show up without pc
			capture noisily su sdu`model', detail
			scalar sdu`model'med = r(p50)

			capture noisily su sdx`model', detail
			scalar sdx`model'med = r(p50)
		} // close loop over models 6 8	
		

		/* Statistics that don't show up for both models (so take them outside the 6 8 loop): */
		// Statistics showing up in 6
		foreach model of numlist 6 {
			foreach wpc in "" "wpc" { // first loop over statistics that exist both without and with control for pc
				capture noisily su FSbetaL2DFI`wpc'`model', detail
				scalar FSbetaL2DFI`wpc'`model'med = r(p50)

				capture noisily su OVbetaL2DFI`wpc'`model', detail
				scalar OVbetaL2DFI`wpc'`model'med = r(p50)
				
			} // end wpc loop
			// some statistics only show up with pc or without pc
			capture noisily su corrL2DFIu`model', detail
			scalar corrL2DFIu`model'med = r(p50)

			capture noisily su corrL2DFIx`model', detail
			scalar corrL2DFIx`model'med = r(p50)	
			
			capture noisily su FSbetaL2pc`model', detail
			scalar FSbetaL2pc`model'med = r(p50)

			capture noisily su OVbetaL2pc`model', detail
			scalar OVbetaL2pc`model'med = r(p50)
		
			capture noisily su corrL2pcu`model', detail
			scalar corrL2pcu`model'med = r(p50)

			capture noisily su corrL2pcx`model', detail
			scalar corrL2pcx`model'med = r(p50)
		} // end loop over model 6


		// now for statistics showing up in 8
		foreach model of numlist 8 { // start loop over model 8
			foreach wpc in "" "wpc" { // first loop over statistics that exist without and with control for pc
				capture noisily su FSbetaDLDFI`wpc'`model', detail
				scalar FSbetaDLDFI`wpc'`model'med = r(p50)

				capture noisily su OVbetaDLDFI`wpc'`model', detail
				scalar OVbetaDLDFI`wpc'`model'med = r(p50)

			} // close loop over statistics without and with control for pc 
			// some statistics that only show up with pc or without pc
			capture noisily su corrDLDFIu`model', detail
			scalar corrDLDFIu`model'med = r(p50)
			
			capture noisily su corrDLDFIx`model', detail
			scalar corrDLDFIx`model'med = r(p50)

			capture noisily su FSbetaDLpc`model', detail
			scalar FSbetaDLpc`model'med = r(p50)
						
			capture noisily su OVbetaDLpc`model', detail
			scalar OVbetaDLpc`model'med = r(p50)

			capture noisily su corrDLpcu`model', detail
			scalar corrDLpcu`model'med = r(p50)

			capture noisily su corrDLpcx`model', detail
			scalar corrDLpcx`model'med = r(p50)
		} // end loop over model 8

			
		/* Manually calculate bias for some of the models: */
		// Biases showing up in 6
		foreach model of numlist 6 {
			// bias based on DFI instrument
			gen double DFIbiasDFIinv`model' = (corrL2DFIu`model'/corrL2DFIx`model')*(sdu`model'/sdx`model')
			su DFIbiasDFIinv`model', detail
			scalar DFIbiasDFIinv`model'mean = r(mean)
			scalar DFIbiasDFIinv`model'med = r(p50)
		} // end loop over models 6


		// Biases showing up in 8
		foreach model of numlist 8 {
			// bias based on DFI instrument
			gen double DFIbiasDFIinv`model' = (corrDLDFIu`model'/corrDLDFIx`model')*(sdu`model'/sdx`model')
			su DFIbiasDFIinv`model', detail
			scalar DFIbiasDFIinv`model'mean = r(mean)
			scalar DFIbiasDFIinv`model'med = r(p50)
		} // end loop over model 8
		
		count if maxdbpercnumprojerover2 >= 1 & maxdbpercnumprojerover2 != .
		scalar countmaxdbpercnumprojerover2exc1 = r(N)
		
		su medinvDFIvsprivate, detail
		scalar medmedinvDFIvsprivate = r(p50)		

		scalar empty = .
		scalar number = `num'

		// Put statistics in matrix:
		matrix GMMzeroadd_`num' = (number \ empty \ empty \ DFIinv1mean \ DFIinv1med \ DFIinv1sd /// 
		\ pzeroaddpercreject1 \ pfulladdpercreject1 ///
		\ lagdep1mean \ lagdep1med \ lagdep1sd \ numinstr1 \ m1percpass1 ///
		\ m2percpass1 \ hansenpercpass1 \ sarganpercpass1 \ hansenpercpasslev1 \ hansenpercpasslagdep1 /// 
		\ hansenpercpassDFIinvdiff1 \ hansenpercpassDFIinvlev1 \ condFDFI1med ///
		\ condFDFIpercrejunderid1 ///
		\ empty ///
		\ DFIinvwpc1mean \ DFIinvwpc1med \ DFIinvwpc1sd \ pzeroaddpercrejectwpc1 \ pfulladdpercrejectwpc1 ///
		\ lagdepwpc1mean \ lagdepwpc1med \ lagdepwpc1sd \ numinstrwpc1 \ m1percpasswpc1 ///
		\ m2percpasswpc1 \ hansenpercpasswpc1 \ sarganpercpasswpc1 \ hansenpercpasslevwpc1 \ hansenpercpasslagdepwpc1 /// 
		\ hansenpercpassDFIinvdiffwpc1 \ hansenpercpassDFIinvlevwpc1 \ hansenpercpasspc1 \ condFDFIwpc1med ///
		\ condFDFIpercrejunderidwpc1 ///
		\ empty \ empty ///
		\ DFIinv2mean \ DFIinv2med \ DFIinv2sd \ pzeroaddpercreject2 \ pfulladdpercreject2 ///
		\ lagdep2mean \ lagdep2med \ lagdep2sd \ numinstr2 \ m1percpass2 ///
		\ m2percpass2 \ hansenpercpass2 \ sarganpercpass2 \ hansenpercpasslev2 \ hansenpercpasslagdep2 /// 
		\ hansenpercpassDFIinvdiff2 \ hansenpercpassDFIinvlev2 \ condFDFI2med ///
		\ condFDFIpercrejunderid2 ///
		\ empty ///
		\ DFIinvwpc2mean \ DFIinvwpc2med \ DFIinvwpc2sd \ pzeroaddpercrejectwpc2 \ pfulladdpercrejectwpc2 ///
		\ lagdepwpc2mean \ lagdepwpc2med \ lagdepwpc2sd \ numinstrwpc2 \ m1percpasswpc2 ///
		\ m2percpasswpc2 \ hansenpercpasswpc2 \ sarganpercpasswpc2 \ hansenpercpasslevwpc2 \ hansenpercpasslagdepwpc2 /// 
		\ hansenpercpassDFIinvdiffwpc2 \ hansenpercpassDFIinvlevwpc2 \ hansenpercpasspc2 \ condFDFIwpc2med ///
		\ condFDFIpercrejunderidwpc2 ///
		\ empty \ empty ///
		\ DFIinv3mean \ DFIinv3med \ DFIinv3sd \ pzeroaddpercreject3 \ pfulladdpercreject3 ///
		\ lagdep3mean \ lagdep3med \ lagdep3sd \ numinstr3 \ m1percpass3 ///
		\ m2percpass3 \ hansenpercpass3 \ sarganpercpass3 \ hansenpercpasslev3 \ hansenpercpasslagdep3 /// 
		\ hansenpercpassDFIinvdiff3 \ hansenpercpassDFIinvlev3 \ condFDFI3med ///
		\ condFDFIpercrejunderid3 ///
		\ empty ///
		\ DFIinvwpc3mean \ DFIinvwpc3med \ DFIinvwpc3sd \ pzeroaddpercrejectwpc3 \ pfulladdpercrejectwpc3 ///
		\ lagdepwpc3mean \ lagdepwpc3med \ lagdepwpc3sd \ numinstrwpc3 \ m1percpasswpc3 ///
		\ m2percpasswpc3 \ hansenpercpasswpc3 \ sarganpercpasswpc3 \ hansenpercpasslevwpc3 \ hansenpercpasslagdepwpc3 /// 
		\ hansenpercpassDFIinvdiffwpc3 \ hansenpercpassDFIinvlevwpc3 \ hansenpercpasspc3 \ condFDFIwpc3med ///
		\ condFDFIpercrejunderidwpc3 ///
		\ empty \ empty ///
		\ DFIinv4mean \ DFIinv4med \ DFIinv4sd \ pzeroaddpercreject4 \ pfulladdpercreject4 ///
		\ lagdep4mean \ lagdep4med \ lagdep4sd \ numinstr4 \ m1percpass4 ///
		\ m2percpass4 \ hansenpercpass4 \ sarganpercpass4 \ hansenpercpasslev4 \ hansenpercpasslagdep4 /// 
		\ hansenpercpassDFIinvdiff4 \ hansenpercpassDFIinvlev4 \ condFDFI4med ///
		\ condFDFIpercrejunderid4 ///
		\ empty ///
		\ DFIinvwpc4mean \ DFIinvwpc4med \ DFIinvwpc4sd \ pzeroaddpercrejectwpc4 \ pfulladdpercrejectwpc4 ///
		\ lagdepwpc4mean \ lagdepwpc4med \ lagdepwpc4sd \ numinstrwpc4 \ m1percpasswpc4 ///
		\ m2percpasswpc4 \ hansenpercpasswpc4 \ sarganpercpasswpc4 \ hansenpercpasslevwpc4 \ hansenpercpasslagdepwpc4 /// 
		\ hansenpercpassDFIinvdiffwpc4 \ hansenpercpassDFIinvlevwpc4 \ hansenpercpasspc4 \ condFDFIwpc4med ///
		\ condFDFIpercrejunderidwpc4 ///
		\ empty \ empty ///
		\ DFIinv5mean \ DFIinv5med \ DFIinv5sd \ pzeroaddpercreject5 \ pfulladdpercreject5 ///
		\ lagdep5mean \ lagdep5med \ lagdep5sd \ numinstr5 \ m1percpass5 ///
		\ m2percpass5 \ hansenpercpass5 \ sarganpercpass5 \ hansenpercpasslev5 \ hansenpercpasslagdep5 /// 
		\ hansenpercpassDFIinvdiff5 \ hansenpercpassDFIinvlev5 \ condFDFI5med ///
		\ condFDFIpercrejunderid5 ///
		\ empty ///
		\ DFIinvwpc5mean \ DFIinvwpc5med \ DFIinvwpc5sd \ pzeroaddpercrejectwpc5 \ pfulladdpercrejectwpc5 ///
		\ lagdepwpc5mean \ lagdepwpc5med \ lagdepwpc5sd \ numinstrwpc5 \ m1percpasswpc5 ///
		\ m2percpasswpc5 \ hansenpercpasswpc5 \ sarganpercpasswpc5 \ hansenpercpasslevwpc5 \ hansenpercpasslagdepwpc5 /// 
		\ hansenpercpassDFIinvdiffwpc5 \ hansenpercpassDFIinvlevwpc5 \ hansenpercpasspc5 \ condFDFIwpc5med ///
		\ condFDFIpercrejunderidwpc5 ///
		\ empty \ empty)

		
		matrix GMMzeroadd_`num' = (GMMzeroadd_`num' \ DFIinv6mean \ DFIinv6med \ DFIinv6sd \ pzeroaddpercreject6 \ pfulladdpercreject6 \ FSrobF6med ///
		\ FSbetaL2DFI6med \ OVbetaL2DFI6med \ corrL2DFIu6med \ corrL2DFIx6med \ sdu6med \ sdx6med \ DFIbiasDFIinv6mean \ DFIbiasDFIinv6med ///
		\ empty ///
		\ DFIinvwpc6mean \ DFIinvwpc6med \ DFIinvwpc6sd \ pzeroaddpercrejectwpc6 \ pfulladdpercrejectwpc6 \ FSrobFwpc6med ///
		\ FSbetaL2DFIwpc6med \ FSbetaL2pc6med \ OVbetaL2DFIwpc6med \ OVbetaL2pc6med /// 
		\ empty \ empty ///
		\ DFIinv7mean \ DFIinv7med \ DFIinv7sd \ pzeroaddpercreject7 \ pfulladdpercreject7 ///
		\ lagdep7mean \ lagdep7med \ lagdep7sd \ numinstr7 \ m1percpass7 ///
		\ m2percpass7 \ hansenpercpass7 \ sarganpercpass7 \ hansenpercpasslev7 \ hansenpercpasslagdep7 /// 
		\ hansenpercpassDFIinvdiff7 \ hansenpercpassDFIinvlev7 \ condFDFI7med ///
		\ condFDFIpercrejunderid7 ///
		\ empty ///
		\ DFIinvwpc7mean \ DFIinvwpc7med \ DFIinvwpc7sd \ pzeroaddpercrejectwpc7 \ pfulladdpercrejectwpc7 ///
		\ lagdepwpc7mean \ lagdepwpc7med \ lagdepwpc7sd \ numinstrwpc7 \ m1percpasswpc7 ///
		\ m2percpasswpc7 \ hansenpercpasswpc7 \ sarganpercpasswpc7 \ hansenpercpasslevwpc7 \ hansenpercpasslagdepwpc7 /// 
		\ hansenpercpassDFIinvdiffwpc7 \ hansenpercpassDFIinvlevwpc7 \ hansenpercpasspc7 \ condFDFIwpc7med ///
		\ condFDFIpercrejunderidwpc7 ///
		\ empty \ empty ///
		\ DFIinv8mean \ DFIinv8med \ DFIinv8sd \ pzeroaddpercreject8 \ pfulladdpercreject8 \ FSrobF8med ///
		\ FSbetaDLDFI8med \ OVbetaDLDFI8med \ corrDLDFIu8med \ corrDLDFIx8med \ sdu8med \ sdx8med ///
		\ DFIbiasDFIinv8mean \ DFIbiasDFIinv8med ///
		\ empty ///
		\ DFIinvwpc8mean \ DFIinvwpc8med \ DFIinvwpc8sd \ pzeroaddpercrejectwpc8 \ pfulladdpercrejectwpc8 \ FSrobFwpc8med ///
		\ FSbetaDLDFIwpc8med \ FSbetaDLpc8med \ OVbetaDLDFIwpc8med \ OVbetaDLpc8med /// 
		\ empty \ countmaxdbpercnumprojerover2exc1 \ successfulreps \ medmedinvDFIvsprivate)
				
		matrix list GMMzeroadd_`num'

	log close
	} // close loop over generated datasets/experiments


	/* Construct matrices that combine results. */
	/* First table: */
	foreach num of numlist 1/9 {
	if `num'==1 { 
		matrix tableGMMzeroadd = GMMzeroadd_`num'
	}
	else { 
		matrix tableGMMzeroadd=(tableGMMzeroadd, GMMzeroadd_`num')
	}        
	}


	/* Export to Excel and clean up tables. */
	/* First table: */
	putexcel set "./Tables/GMMzeroaddtable_`option'", replace
	putexcel B2 = matrix(tableGMMzeroadd) // starting point of table
	//
	local row 3
	//
	putexcel A`row++' = "MODEL 1: SYSTEM GMM, STATIC MODEL, 1 LAG"
	putexcel A`row++' = "WITHOUT PC"
	putexcel A`row++' = "DFI coeff. mean"
	putexcel A`row++' = "DFI coeff. median"
	putexcel A`row++' = "DFI coeff. st. dev."
	putexcel A`row++' = "% reject zero additionality"
	putexcel A`row++' = "% reject full additionality"
	putexcel A`row++' = "Lag dep coeff. mean"
	putexcel A`row++' = "Lag dep coeff. median"
	putexcel A`row++' = "Lag dep coeff. st. dev."
	putexcel A`row++' = "# instruments"
	putexcel A`row++' = "m1 % pass"
	putexcel A`row++' = "m2 % pass"
	putexcel A`row++' = "Hansen % pass"
	putexcel A`row++' = "Sargan % pass"
	putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
	putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
	putexcel A`row++' = "Conditional F median"
	putexcel A`row++' = "Conditional F % reject underidentification"
	//
	putexcel A`row++' = "WITH PC"
	putexcel A`row++' = "DFI coeff. mean"
	putexcel A`row++' = "DFI coeff. median"
	putexcel A`row++' = "DFI coeff. st. dev."
	putexcel A`row++' = "% reject zero additionality"
	putexcel A`row++' = "% reject full additionality"
	putexcel A`row++' = "Lag dep coeff. mean"
	putexcel A`row++' = "Lag dep coeff. median"
	putexcel A`row++' = "Lag dep coeff. st. dev."
	putexcel A`row++' = "# instruments"
	putexcel A`row++' = "m1 % pass"
	putexcel A`row++' = "m2 % pass"
	putexcel A`row++' = "Hansen % pass"
	putexcel A`row++' = "Sargan % pass"
	putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
	putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen pc % pass"
	putexcel A`row++' = "Conditional F median"
	putexcel A`row++' = "Conditional F % reject underidentification"
	//
	//
	putexcel A`row++' = "MODEL 2: SYSTEM GMM, WITH LDV, 1 LAG"
	putexcel A`row++' = "WITHOUT PC"
	putexcel A`row++' = "DFI coeff. mean"
	putexcel A`row++' = "DFI coeff. median"
	putexcel A`row++' = "DFI coeff. st. dev."
	putexcel A`row++' = "% reject zero additionality"
	putexcel A`row++' = "% reject full additionality"
	putexcel A`row++' = "Lag dep coeff. mean"
	putexcel A`row++' = "Lag dep coeff. median"
	putexcel A`row++' = "Lag dep coeff. st. dev."
	putexcel A`row++' = "# instruments"
	putexcel A`row++' = "m1 % pass"
	putexcel A`row++' = "m2 % pass"
	putexcel A`row++' = "Hansen % pass"
	putexcel A`row++' = "Sargan % pass"
	putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
	putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
	putexcel A`row++' = "Conditional F median"
	putexcel A`row++' = "Conditional F % reject underidentification"
	//
	putexcel A`row++' = "WITH PC"
	putexcel A`row++' = "DFI coeff. mean"
	putexcel A`row++' = "DFI coeff. median"
	putexcel A`row++' = "DFI coeff. st. dev."
	putexcel A`row++' = "% reject zero additionality"
	putexcel A`row++' = "% reject full additionality"
	putexcel A`row++' = "Lag dep coeff. mean"
	putexcel A`row++' = "Lag dep coeff. median"
	putexcel A`row++' = "Lag dep coeff. st. dev."
	putexcel A`row++' = "# instruments"
	putexcel A`row++' = "m1 % pass"
	putexcel A`row++' = "m2 % pass"
	putexcel A`row++' = "Hansen % pass"
	putexcel A`row++' = "Sargan % pass"
	putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
	putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen pc % pass"
	putexcel A`row++' = "Conditional F median"
	putexcel A`row++' = "Conditional F % reject underidentification"
	//
	//
	putexcel A`row++' = "MODEL 3: SYSTEM GMM, STATIC MODEL, 4 LAGS"
	putexcel A`row++' = "WITHOUT PC"
	putexcel A`row++' = "DFI coeff. mean"
	putexcel A`row++' = "DFI coeff. median"
	putexcel A`row++' = "DFI coeff. st. dev."
	putexcel A`row++' = "% reject zero additionality"
	putexcel A`row++' = "% reject full additionality"
	putexcel A`row++' = "Lag dep coeff. mean"
	putexcel A`row++' = "Lag dep coeff. median"
	putexcel A`row++' = "Lag dep coeff. st. dev."
	putexcel A`row++' = "# instruments"
	putexcel A`row++' = "m1 % pass"
	putexcel A`row++' = "m2 % pass"
	putexcel A`row++' = "Hansen % pass"
	putexcel A`row++' = "Sargan % pass"
	putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
	putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
	putexcel A`row++' = "Conditional F median"
	putexcel A`row++' = "Conditional F % reject underidentification"
	//
	putexcel A`row++' = "WITH PC"
	putexcel A`row++' = "DFI coeff. mean"
	putexcel A`row++' = "DFI coeff. median"
	putexcel A`row++' = "DFI coeff. st. dev."
	putexcel A`row++' = "% reject zero additionality"
	putexcel A`row++' = "% reject full additionality"
	putexcel A`row++' = "Lag dep coeff. mean"
	putexcel A`row++' = "Lag dep coeff. median"
	putexcel A`row++' = "Lag dep coeff. st. dev."
	putexcel A`row++' = "# instruments"
	putexcel A`row++' = "m1 % pass"
	putexcel A`row++' = "m2 % pass"
	putexcel A`row++' = "Hansen % pass"
	putexcel A`row++' = "Sargan % pass"
	putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
	putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen pc % pass"
	putexcel A`row++' = "Conditional F median"
	putexcel A`row++' = "Conditional F % reject underidentification"
	//
	//
	putexcel A`row++' = "MODEL 4: SYSTEM GMM, WITH LDV, 4 LAGS"
	putexcel A`row++' = "WITHOUT PC"
	putexcel A`row++' = "DFI coeff. mean"
	putexcel A`row++' = "DFI coeff. median"
	putexcel A`row++' = "DFI coeff. st. dev."
	putexcel A`row++' = "% reject zero additionality"
	putexcel A`row++' = "% reject full additionality"
	putexcel A`row++' = "Lag dep coeff. mean"
	putexcel A`row++' = "Lag dep coeff. median"
	putexcel A`row++' = "Lag dep coeff. st. dev."
	putexcel A`row++' = "# instruments"
	putexcel A`row++' = "m1 % pass"
	putexcel A`row++' = "m2 % pass"
	putexcel A`row++' = "Hansen % pass"
	putexcel A`row++' = "Sargan % pass"
	putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
	putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
	putexcel A`row++' = "Conditional F median"
	putexcel A`row++' = "Conditional F % reject underidentification"
	//
	putexcel A`row++' = "WITH PC"
	putexcel A`row++' = "DFI coeff. mean"
	putexcel A`row++' = "DFI coeff. median"
	putexcel A`row++' = "DFI coeff. st. dev."
	putexcel A`row++' = "% reject zero additionality"
	putexcel A`row++' = "% reject full additionality"
	putexcel A`row++' = "Lag dep coeff. mean"
	putexcel A`row++' = "Lag dep coeff. median"
	putexcel A`row++' = "Lag dep coeff. st. dev."
	putexcel A`row++' = "# instruments"
	putexcel A`row++' = "m1 % pass"
	putexcel A`row++' = "m2 % pass"
	putexcel A`row++' = "Hansen % pass"
	putexcel A`row++' = "Sargan % pass"
	putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
	putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen pc % pass"
	putexcel A`row++' = "Conditional F median"
	putexcel A`row++' = "Conditional F % reject underidentification"
	//
	//
	putexcel A`row++' = "MODEL 5: DIFFERENCE GMM, STATIC MODEL, 1 LAG"
	putexcel A`row++' = "WITHOUT PC"
	putexcel A`row++' = "DFI coeff. mean"
	putexcel A`row++' = "DFI coeff. median"
	putexcel A`row++' = "DFI coeff. st. dev."
	putexcel A`row++' = "% reject zero additionality"
	putexcel A`row++' = "% reject full additionality"
	putexcel A`row++' = "Lag dep coeff. mean"
	putexcel A`row++' = "Lag dep coeff. median"
	putexcel A`row++' = "Lag dep coeff. st. dev."
	putexcel A`row++' = "# instruments"
	putexcel A`row++' = "m1 % pass"
	putexcel A`row++' = "m2 % pass"
	putexcel A`row++' = "Hansen % pass"
	putexcel A`row++' = "Sargan % pass"
	putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
	putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
	putexcel A`row++' = "Conditional F median"
	putexcel A`row++' = "Conditional F % reject underidentification"
	//
	putexcel A`row++' = "WITH PC"
	putexcel A`row++' = "DFI coeff. mean"
	putexcel A`row++' = "DFI coeff. median"
	putexcel A`row++' = "DFI coeff. st. dev."
	putexcel A`row++' = "% reject zero additionality"
	putexcel A`row++' = "% reject full additionality"
	putexcel A`row++' = "Lag dep coeff. mean"
	putexcel A`row++' = "Lag dep coeff. median"
	putexcel A`row++' = "Lag dep coeff. st. dev."
	putexcel A`row++' = "# instruments"
	putexcel A`row++' = "m1 % pass"
	putexcel A`row++' = "m2 % pass"
	putexcel A`row++' = "Hansen % pass"
	putexcel A`row++' = "Sargan % pass"
	putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
	putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen pc % pass"
	putexcel A`row++' = "Conditional F median"
	putexcel A`row++' = "Conditional F % reject underidentification"
	//
	//
	putexcel A`row++' = "MODEL 6: IV ON DIFFERENCED EQN., STATIC MODEL, 1 LAG"
	putexcel A`row++' = "WITHOUT PC"
	putexcel A`row++' = "DFI coeff. mean"
	putexcel A`row++' = "DFI coeff. median"
	putexcel A`row++' = "DFI coeff. st. dev."
	putexcel A`row++' = "% reject zero additionality"
	putexcel A`row++' = "% reject full additionality"
	putexcel A`row++' = "FS robust F median"
	putexcel A`row++' = "FS coeff. L2 DFI inv. median"
	putexcel A`row++' = "OV coeff. L2 DFI inv. median"
	putexcel A`row++' = "Corr(L2 DFI inv.,du) median"
	putexcel A`row++' = "Corr(L2 DFI inv.,dx) median"
	putexcel A`row++' = "St. dev. du median"
	putexcel A`row++' = "St. dev. dx median"
	putexcel A`row++' = "Mean bias based on DFI inv. instr."
	putexcel A`row++' = "Median bias based on DFI inv. instr."
	//
	putexcel A`row++' = "WITH PC"
	putexcel A`row++' = "DFI coeff. mean"
	putexcel A`row++' = "DFI coeff. median"
	putexcel A`row++' = "DFI coeff. st. dev."
	putexcel A`row++' = "% reject zero additionality"
	putexcel A`row++' = "% reject full additionality"
	putexcel A`row++' = "FS robust F median"
	putexcel A`row++' = "FS coeff. L2 DFI inv. median"
	putexcel A`row++' = "FS coeff. L2 pc median"
	putexcel A`row++' = "OV coeff. L2 DFI inv. median"
	putexcel A`row++' = "OV coeff. L2 pc median"
	//
	//
	putexcel A`row++' = "MODEL 7: LEVELS GMM, STATIC MODEL, 1 LAG"
	putexcel A`row++' = "WITHOUT PC"
	putexcel A`row++' = "DFI coeff. mean"
	putexcel A`row++' = "DFI coeff. median"
	putexcel A`row++' = "DFI coeff. st. dev."
	putexcel A`row++' = "% reject zero additionality"
	putexcel A`row++' = "% reject full additionality"
	putexcel A`row++' = "Lag dep coeff. mean"
	putexcel A`row++' = "Lag dep coeff. median"
	putexcel A`row++' = "Lag dep coeff. st. dev."
	putexcel A`row++' = "# instruments"
	putexcel A`row++' = "m1 % pass"
	putexcel A`row++' = "m2 % pass"
	putexcel A`row++' = "Hansen % pass"
	putexcel A`row++' = "Sargan % pass"
	putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
	putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
	putexcel A`row++' = "Conditional F median"
	putexcel A`row++' = "Conditional F % reject underidentification"
	//
	putexcel A`row++' = "WITH PC"
	putexcel A`row++' = "DFI coeff. mean"
	putexcel A`row++' = "DFI coeff. median"
	putexcel A`row++' = "DFI coeff. st. dev."
	putexcel A`row++' = "% reject zero additionality"
	putexcel A`row++' = "% reject full additionality"
	putexcel A`row++' = "Lag dep coeff. mean"
	putexcel A`row++' = "Lag dep coeff. median"
	putexcel A`row++' = "Lag dep coeff. st. dev."
	putexcel A`row++' = "# instruments"
	putexcel A`row++' = "m1 % pass"
	putexcel A`row++' = "m2 % pass"
	putexcel A`row++' = "Hansen % pass"
	putexcel A`row++' = "Sargan % pass"
	putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
	putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
	putexcel A`row++' = "Diff.-in-Hansen pc % pass"
	putexcel A`row++' = "Conditional F median"
	putexcel A`row++' = "Conditional F % reject underidentification"
	//
	//
	putexcel A`row++' = "MODEL 8: IV ON LEVELS EQN, STATIC MODEL, 1 LAG"
	putexcel A`row++' = "WITHOUT PC"
	putexcel A`row++' = "DFI coeff. mean"
	putexcel A`row++' = "DFI coeff. median"
	putexcel A`row++' = "DFI coeff. st. dev."
	putexcel A`row++' = "% reject zero additionality"
	putexcel A`row++' = "% reject full additionality"
	putexcel A`row++' = "FS robust F median"
	putexcel A`row++' = "FS coeff. DL DFI inv. median"
	putexcel A`row++' = "OV coeff. DL DFI inv. median"
	putexcel A`row++' = "Corr(DL DFI inv.,u) median"
	putexcel A`row++' = "Corr(DL DFI inv.,x) median"
	putexcel A`row++' = "St. dev. u median"
	putexcel A`row++' = "St. dev. x median"
	putexcel A`row++' = "Mean bias based on DFI inv. instr."
	putexcel A`row++' = "Median bias based on DFI inv. instr."
	//
	putexcel A`row++' = "WITH PC"
	putexcel A`row++' = "DFI coeff. mean"
	putexcel A`row++' = "DFI coeff. median"
	putexcel A`row++' = "DFI coeff. st. dev."
	putexcel A`row++' = "% reject zero additionality"
	putexcel A`row++' = "% reject full additionality"
	putexcel A`row++' = "FS robust F median"
	putexcel A`row++' = "FS coeff. DL DFI inv. median"
	putexcel A`row++' = "FS coeff. DL pc median"
	putexcel A`row++' = "OV coeff. DL DFI inv. median"
	putexcel A`row++' = "OV coeff. DL pc median"
	//
	putexcel A`row++' = " "
	putexcel A`row++' = "Number of datasets where max db exceeds # proj. with er > 2"
	putexcel A`row++' = "# successful replications"
	putexcel A`row++' = "Med. of med. DFI inv/private"
	//
	putexcel B1= "No noise in pc"
	putexcel C1= "Noise 0.5"
	putexcel D1= "Noise 1"
	putexcel E1= "pc mean closer, noise 0.5"
	putexcel F1= "pc mean = 2, noise 0.5"
	putexcel G1= "upward drift, noise 0.5"
	putexcel H1= "fixed types, noise 0.5"
	putexcel I1= "fixed types, upward drift, noise 0.5"
	putexcel J1= "fixed types, downward drift, noise 0.5"

	
	/* Now generate table to export to TeX, using texdoc. */
	/* Baseline table. */
	texdoc init "`tablesexport'/GMMexport_zeroadd_`option'.tex", replace force
	tex  								  & \mcolsfe{(1)} 				      & \mcolsfe{(2)} 				         & \mcolsfe{(3)} 						 & \mcolsfe{(4)} 					    & \mcolsfe{(5)} 				    & \mcolsfe{(6)} 				       & \mcolsfe{(7)} 						   & \mcolsfe{(8)} \\
	tex LDV                               & \mcolsfe{no}                      & \mcolsfe{no}                         & \mcolsfe{no}                          & \mcolsfe{no}                         & \mcolsfe{yes}                     & \mcolsfe{yes}                        & \mcolsfe{yes}                         & \mcolsfe{yes} \\
	tex $\mathit{pc}$                     & \mcolsfe{excl.}                   & \mcolsfe{$\sigma_m^{2} = 1$}         & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}} & \mcolsfe{$\sigma_m^{2} = 0$}         & \mcolsfe{excl.}                   & \mcolsfe{$\sigma_m^{2} = 1$}         & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}} & \mcolsfe{$\sigma_m^{2} = 0$} \\
	tex \cmidrule{1-9}
	tex Med.\ $\widehat{\beta}_{sysGMM}$  & `sysGMM1betadfimedian1'           & `sysGMMwpc1betadfimedian3'           & `sysGMMwpc1betadfimedian2'            & `sysGMMwpc1betadfimedian1'           & `sysGMM2betadfimedian1'           & `sysGMMwpc2betadfimedian3'           & `sysGMMwpc2betadfimedian2'            & `sysGMMwpc2betadfimedian1' \\
	tex Std.\ dev.\	                      & `sysGMM1betadfisd1'               & `sysGMMwpc1betadfisd3'               & `sysGMMwpc1betadfisd2'                & `sysGMMwpc1betadfisd1'               & `sysGMM2betadfisd1'               & `sysGMMwpc2betadfisd3'               & `sysGMMwpc2betadfisd2'                & `sysGMMwpc2betadfisd1' \\
	tex \% reject $\beta \leqslant 0$     & \mcc{`sysGMMzeroaddpercreject11'} & \mcc{`sysGMMzeroaddpercrejectwpc13'} & \mcc{`sysGMMzeroaddpercrejectwpc12'}  & \mcc{`sysGMMzeroaddpercrejectwpc11'} & \mcc{`sysGMMzeroaddpercreject21'} & \mcc{`sysGMMzeroaddpercrejectwpc23'} & \mcc{`sysGMMzeroaddpercrejectwpc22'}  & \mcc{`sysGMMzeroaddpercrejectwpc21'} \\
	tex Hansen \% pass                    & \mcc{`sysGMMhansenpercpass11'}    & \mcc{`sysGMMhansenpercpasswpc13'}    & \mcc{`sysGMMhansenpercpasswpc12'}     & \mcc{`sysGMMhansenpercpasswpc11'}    & \mcc{`sysGMMhansenpercpass21'}    & \mcc{`sysGMMhansenpercpasswpc23'}    & \mcc{`sysGMMhansenpercpasswpc22'}     & \mcc{`sysGMMhansenpercpasswpc21'} \\
	tex Med.\ cond.\ F                    & \mcc{`sysGMMcondFDFI1med1'}       & \mcc{`sysGMMcondFDFIwpc1med3'}       & \mcc{`sysGMMcondFDFIwpc1med2'}        & \mcc{`sysGMMcondFDFIwpc1med1'}       & \mcc{`sysGMMcondFDFI2med1'}       & \mcc{`sysGMMcondFDFIwpc2med3'}       & \mcc{`sysGMMcondFDFIwpc2med2'}        & \mcc{`sysGMMcondFDFIwpc2med1'} \\
	tex \mbox{\% reject underid.}         & \mcc{`sysGMMcondFDFIpercrej11'}   & \mcc{`sysGMMcondFDFIpercrejwpc13'}   & \mcc{`sysGMMcondFDFIpercrejwpc12'}    & \mcc{`sysGMMcondFDFIpercrejwpc11'}   & \mcc{`sysGMMcondFDFIpercrej21'}   & \mcc{`sysGMMcondFDFIpercrejwpc23'}   & \mcc{`sysGMMcondFDFIpercrejwpc22'}    & \mcc{`sysGMMcondFDFIpercrejwpc21'} \\
	tex \bottomrule
	texdoc close


	/* Additional experiments. */
	texdoc init "`tablesexport'/GMMexport_zeroadd_2_`option'.tex", replace force
	tex  								  & \mcolsfe{(1)} 				      & \mcolsfe{(2)} 				                                    & \mcolsfe{(3)} 				    & \mcolsfe{(4)} 					                           & \mcolsfe{(5)} 				       & \mcolsfe{(6)} 				                           & \mcolsfe{(7)} 						 & \mcolsfe{(8)} \\
	tex Experiment description            & \multicolumn{2}{c}{\begin{tabular}{@{}c@{}}Upward trend \tabularnewline in DFI budget\end{tabular}} & \multicolumn{2}{c}{\begin{tabular}{@{}c@{}}$\mu_c$ closer \tabularnewline together\end{tabular}} & \multicolumn{2}{c}{\begin{tabular}{@{}c@{}}$\mu_c$ the \tabularnewline same\end{tabular}} &  \multicolumn{2}{c}{\begin{tabular}{@{}c@{}}Upward trend \tabularnewline in DFI budget, \tabularnewline fixed types\end{tabular}} \\
	tex $\mathit{pc}$                     & \mcolsfe{excl.}                   & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}}                           & \mcolsfe{excl.}                   & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}}                        & \mcolsfe{excl.}                   & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}}                 & \mcolsfe{excl.}                     & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}} \\
	tex $\sigma_{db}$                     & \mcc{0}                           & \mcc{0}                                                         & \mcc{0.15}                        & \mcc{0.15}                                                   & \mcc{0.15}                        & \mcc{0.15}                                            & \mcc{0}                             & \mcc{0} \\
	tex $\mathit{drift}$                  & \mcc{0.05}                        & \mcc{0.05}                                                      & \mcc{0}                           & \mcc{0}                                                      & \mcc{0}                           & \mcc{0}                                               & \mcc{0.05}                          & \mcc{0.05} \\
	tex $\mu_c$                           & \mcc{$\left[0, 2, 4\right]$}      & \mcc{$\left[0, 2, 4\right]$}                                    & \mcc{$\left[1, 2, 3\right]$}      & \mcc{$\left[1, 2, 3\right]$}                                 & \mcc{$\left[2, 2, 2\right]$}      & \mcc{$\left[2, 2, 2\right]$}                          & \mcc{$\left[0, 2, 4\right]$}        & \mcc{$\left[0, 2, 4\right]$} \\
	tex $\Delta$ types                    & \mcolsfe{default}                 & \mcolsfe{default}                                               & \mcolsfe{default}                 & \mcolsfe{default}                                            & \mcolsfe{default}                 & \mcolsfe{default}                                     & \mcolsfe{fixed}                     & \mcolsfe{fixed} \\
	tex \cmidrule{1-9}                                                                  
	tex Med.\ $\widehat{\beta}_{sysGMM}$  & `sysGMM1betadfimedian6'           & `sysGMMwpc1betadfimedian6'                                      & `sysGMM1betadfimedian4'           & `sysGMMwpc1betadfimedian4'                                   & `sysGMM1betadfimedian5'           & `sysGMMwpc1betadfimedian5'                            & `sysGMM1betadfimedian8'            & `sysGMMwpc1betadfimedian8' \\
	tex Std.\ dev.\	                      & `sysGMM1betadfisd6'               & `sysGMMwpc1betadfisd6'                                          & `sysGMM1betadfisd4'               & `sysGMMwpc1betadfisd4'                                       & `sysGMM1betadfisd5'               & `sysGMMwpc1betadfisd5'                                & `sysGMM1betadfisd8'                & `sysGMMwpc1betadfisd8' \\
	tex \% reject $\beta \leqslant 0$     & \mcc{`sysGMMzeroaddpercreject16'} & \mcc{`sysGMMzeroaddpercrejectwpc16'}                            & \mcc{`sysGMMzeroaddpercreject14'} & \mcc{`sysGMMzeroaddpercrejectwpc14'}                         & \mcc{`sysGMMzeroaddpercreject15'} & \mcc{`sysGMMzeroaddpercrejectwpc15'}                  & \mcc{`sysGMMzeroaddpercreject18'}  & \mcc{`sysGMMzeroaddpercrejectwpc18'} \\
	tex Hansen \% pass                    & \mcc{`sysGMMhansenpercpass16'}    & \mcc{`sysGMMhansenpercpasswpc16'}                               & \mcc{`sysGMMhansenpercpass14'}    & \mcc{`sysGMMhansenpercpasswpc14'}                            & \mcc{`sysGMMhansenpercpass15'}    & \mcc{`sysGMMhansenpercpasswpc15'}                     & \mcc{`sysGMMhansenpercpass18'}     & \mcc{`sysGMMhansenpercpasswpc18'} \\
	tex Med.\ cond.\ F                    & \mcc{`sysGMMcondFDFI1med6'}       & \mcc{`sysGMMcondFDFIwpc1med6'}                                  & \mcc{`sysGMMcondFDFI1med4'}       & \mcc{`sysGMMcondFDFIwpc1med4'}                               & \mcc{`sysGMMcondFDFI1med5'}       & \mcc{`sysGMMcondFDFIwpc1med5'}                        & \mcc{`sysGMMcondFDFI1med8'}        & \mcc{`sysGMMcondFDFIwpc1med8'} \\
	tex \mbox{\% reject underid.}         & \mcc{`sysGMMcondFDFIpercrej16'}   & \mcc{`sysGMMcondFDFIpercrejwpc16'}                              & \mcc{`sysGMMcondFDFIpercrej14'}   & \mcc{`sysGMMcondFDFIpercrejwpc14'}                           & \mcc{`sysGMMcondFDFIpercrej15'}   & \mcc{`sysGMMcondFDFIpercrejwpc15'}                    & \mcc{`sysGMMcondFDFIpercrej18'}    & \mcc{`sysGMMcondFDFIpercrejwpc18'} \\
	tex Med.\ $\widehat{\beta}_{diffGMM}$ & `sysGMM5betadfimedian6'           & `sysGMMwpc5betadfimedian6'                                      & `sysGMM5betadfimedian4'           & `sysGMMwpc5betadfimedian4'                                   & `sysGMM5betadfimedian5'           & `sysGMMwpc5betadfimedian5'                            & `sysGMM5betadfimedian8'            & `sysGMMwpc5betadfimedian8' \\
	tex Med.\ $\widehat{\beta}_{levGMM}$  & `sysGMM7betadfimedian6'           & `sysGMMwpc7betadfimedian6'                                      & `sysGMM7betadfimedian4'           & `sysGMMwpc7betadfimedian4'                                   & `sysGMM7betadfimedian5'           & `sysGMMwpc7betadfimedian5'                            & `sysGMM7betadfimedian8'            & `sysGMMwpc7betadfimedian8' \\	
	tex \bottomrule
	texdoc close

	
} // end loop over exclhighdb or not


*************************************************************************
* GMM WITH FULL ADDITIONALITY
*************************************************************************
foreach num of numlist 1/9 { // start loop over generated datasets/experiments
	clear
	capture log close
	log using "./Generated data/GMMfulladd`num'", replace text
	use "./Generated data/GMMfulladd`num'.dta"


	/* First check if all replications have been successful. */
	egen nummissing = rowmiss(betadfi1-finalnumprojerover2)	
	tab nummissing, missing
	count if nummissing == 0
	scalar successfulreps = r(N)
	foreach var of varlist * { 
		replace `var' = . if nummissing != 0
	}

	
	/* Selected statistics to export to Excel later: */
	foreach model of numlist 1/8 { // start loop over models estimated within each dataset

		foreach wpc in "" "wpc" { // loop over statistics without and with control for pc

			/* Results */
			su betadfi`wpc'`model', detail
			scalar DFIinv`wpc'`model'mean = r(mean)
			scalar DFIinv`wpc'`model'med = r(p50)
			local sysGMM`wpc'`model'betadfimedian`num': di %4.2f DFIinv`wpc'`model'med				
			scalar DFIinv`wpc'`model'sd = r(sd)
			local sysGMM`wpc'`model'betadfisd`num': di %4.2f DFIinv`wpc'`model'sd							
			//
			count if pzeroadd`wpc'`model' < 0.05
			scalar pzeroaddpercreject`wpc'`model' = (r(N)/successfulreps)*100
			//
			count if pfulladd`wpc'`model' < 0.05
			scalar pfulladdpercreject`wpc'`model' = (r(N)/successfulreps)*100
			local sysGMMfulladdpercreject`wpc'`model'`num': di %5.0g pfulladdpercreject`wpc'`model'
			//
			capture noisily su betalagdep`wpc'`model', detail
			scalar lagdep`wpc'`model'mean = r(mean)
			scalar lagdep`wpc'`model'med = r(p50)
			scalar lagdep`wpc'`model'sd = r(sd)
			
			/* Diagnostic checks */
			capture noisily su numinstr`wpc'`model'
			scalar numinstr`wpc'`model' = r(mean)
			// Calculate percentage of diagnostic tests that "pass" (i.e. don't suggest a problem, at a 10% significance level)
			capture noisily count if m1`wpc'`model' < 0 & m1p`wpc'`model' < 0.1 
			scalar m1percpass`wpc'`model' = (r(N)/successfulreps)*100
			if _rc == 111 {
				scalar m1percpass`wpc'`model' = .			
			}			
			
			capture noisily count if m2p`wpc'`model' > 0.1 & m2p`wpc'`model' != .
			scalar m2percpass`wpc'`model' = (r(N)/successfulreps)*100
			if _rc == 111 {
				scalar m2percpass`wpc'`model' = .			
			}
			
			capture noisily count if hansp`wpc'`model' > 0.1 & hansp`wpc'`model' != .
			scalar hansenpercpass`wpc'`model' = (r(N)/successfulreps)*100
			if _rc == 111 {
				scalar hansenpercpass`wpc'`model' = .			
			}
			local sysGMMhansenpercpass`wpc'`model'`num': di %5.0g hansenpercpass`wpc'`model'
			
			capture noisily count if sargp`wpc'`model' > 0.1 & sargp`wpc'`model' != .
			scalar sarganpercpass`wpc'`model' = (r(N)/successfulreps)*100
			if _rc == 111 {
				scalar sarganpercpass`wpc'`model' = .			
			}
			
			foreach moment in lev lagdep DFIinvdiff DFIinvlev { // pc moment condition follows later, outside of wpc loop
				capture noisily count if diffHp_`moment'`wpc'`model' > 0.1 & diffHp_`moment'`wpc'`model' != .
				scalar hansenpercpass`moment'`wpc'`model' = (r(N)/successfulreps)*100
				if _rc == 111 {
					scalar hansenpercpass`moment'`wpc'`model' = .			
				}
			}
			
			capture noisily su condFDFI`wpc'`model', detail
			scalar condFDFI`wpc'`model'med = r(p50)
			local sysGMMcondFDFI`wpc'`model'med`num': di %5.0g condFDFI`wpc'`model'med
						
			capture noisily count if condFDFIp`wpc'`model' < 0.05
			scalar condFDFIpercrejunderid`wpc'`model' = (r(N)/successfulreps)*100
			if _rc == 111 {
				scalar condFDFIpercrejunderid`wpc'`model' = .			
			}
			local sysGMMcondFDFIpercrej`wpc'`model'`num': di %5.0g condFDFIpercrejunderid`wpc'`model'
			
		} // close loop over statistics without and with control for pc 
		
		/* Statistic that only exists in the model with pc */
		capture noisily count if diffHp_pc`model' > 0.1 & diffHp_pc`model' != .
		scalar hansenpercpasspc`model' = (r(N)/successfulreps)*100
		if _rc == 111 {
			scalar hansenpercpasspc`model' = .			
		}

	} // close loop over models estimated within each dataset

	
	/* IV estimation (first statistics that show up in 6, 8) */
	foreach model of numlist 6 8 { // start loop over models 6 8
		foreach wpc in "" "wpc" { // loop over statistics without and with control for pc
			capture noisily su FSrobustF`wpc'`model', detail
			scalar FSrobF`wpc'`model'med = r(p50)
		} // close loop over statistics without and with control for pc 
		// some statistics only show up without pc
		capture noisily su sdu`model', detail
		scalar sdu`model'med = r(p50)

		capture noisily su sdx`model', detail
		scalar sdx`model'med = r(p50)
	} // close loop over models 6 8	
	

	/* Statistics that don't show up for both models (so take them outside the 6 8 loop): */
	// Statistics showing up in 6
	foreach model of numlist 6 {
		foreach wpc in "" "wpc" { // first loop over statistics that exist both without and with control for pc
			capture noisily su FSbetaL2DFI`wpc'`model', detail
			scalar FSbetaL2DFI`wpc'`model'med = r(p50)

			capture noisily su OVbetaL2DFI`wpc'`model', detail
			scalar OVbetaL2DFI`wpc'`model'med = r(p50)
			
		} // end wpc loop
		// some statistics only show up with pc or without pc
		capture noisily su corrL2DFIu`model', detail
		scalar corrL2DFIu`model'med = r(p50)

		capture noisily su corrL2DFIx`model', detail
		scalar corrL2DFIx`model'med = r(p50)	
		
		capture noisily su FSbetaL2pc`model', detail
		scalar FSbetaL2pc`model'med = r(p50)

		capture noisily su OVbetaL2pc`model', detail
		scalar OVbetaL2pc`model'med = r(p50)
	
		capture noisily su corrL2pcu`model', detail
		scalar corrL2pcu`model'med = r(p50)

		capture noisily su corrL2pcx`model', detail
		scalar corrL2pcx`model'med = r(p50)
	} // end loop over model 6


	// now for statistics showing up in 8
	foreach model of numlist 8 { // start loop over model 8
		foreach wpc in "" "wpc" { // first loop over statistics that exist without and with control for pc
			capture noisily su FSbetaDLDFI`wpc'`model', detail
			scalar FSbetaDLDFI`wpc'`model'med = r(p50)

			capture noisily su OVbetaDLDFI`wpc'`model', detail
			scalar OVbetaDLDFI`wpc'`model'med = r(p50)

		} // close loop over statistics without and with control for pc 
		// some statistics that only show up with pc or without pc
		capture noisily su corrDLDFIu`model', detail
		scalar corrDLDFIu`model'med = r(p50)
		
		capture noisily su corrDLDFIx`model', detail
		scalar corrDLDFIx`model'med = r(p50)

		capture noisily su FSbetaDLpc`model', detail
		scalar FSbetaDLpc`model'med = r(p50)
					
		capture noisily su OVbetaDLpc`model', detail
		scalar OVbetaDLpc`model'med = r(p50)

		capture noisily su corrDLpcu`model', detail
		scalar corrDLpcu`model'med = r(p50)

		capture noisily su corrDLpcx`model', detail
		scalar corrDLpcx`model'med = r(p50)
	} // end loop over model 8

		
	/* Manually calculate bias for some of the models: */
	// Biases showing up in 6
	foreach model of numlist 6 {
		// bias based on DFI instrument
		gen double DFIbiasDFIinv`model' = (corrL2DFIu`model'/corrL2DFIx`model')*(sdu`model'/sdx`model')
		su DFIbiasDFIinv`model', detail
		scalar DFIbiasDFIinv`model'mean = r(mean)
		scalar DFIbiasDFIinv`model'med = r(p50)
	} // end loop over models 6


	// Biases showing up in 8
	foreach model of numlist 8 {
		// bias based on DFI instrument
		gen double DFIbiasDFIinv`model' = (corrDLDFIu`model'/corrDLDFIx`model')*(sdu`model'/sdx`model')
		su DFIbiasDFIinv`model', detail
		scalar DFIbiasDFIinv`model'mean = r(mean)
		scalar DFIbiasDFIinv`model'med = r(p50)
	} // end loop over model 8
	
	count if maxdbpercnumprojerover2 >= 1 & maxdbpercnumprojerover2 != .
	scalar countmaxdbpercnumprojerover2exc1 = r(N)
	
	su medinvDFIvsprivate, detail
	scalar medmedinvDFIvsprivate = r(p50)
	
	scalar empty = .
	scalar number = `num'

	// Put statistics in matrix:
	matrix GMMfulladd_`num' = (number \ empty \ empty \ DFIinv1mean \ DFIinv1med \ DFIinv1sd /// 
	\ pzeroaddpercreject1 \ pfulladdpercreject1 ///
	\ lagdep1mean \ lagdep1med \ lagdep1sd \ numinstr1 \ m1percpass1 ///
	\ m2percpass1 \ hansenpercpass1 \ sarganpercpass1 \ hansenpercpasslev1 \ hansenpercpasslagdep1 /// 
	\ hansenpercpassDFIinvdiff1 \ hansenpercpassDFIinvlev1 \ condFDFI1med ///
	\ condFDFIpercrejunderid1 ///
	\ empty ///
	\ DFIinvwpc1mean \ DFIinvwpc1med \ DFIinvwpc1sd \ pzeroaddpercrejectwpc1 \ pfulladdpercrejectwpc1 ///
	\ lagdepwpc1mean \ lagdepwpc1med \ lagdepwpc1sd \ numinstrwpc1 \ m1percpasswpc1 ///
	\ m2percpasswpc1 \ hansenpercpasswpc1 \ sarganpercpasswpc1 \ hansenpercpasslevwpc1 \ hansenpercpasslagdepwpc1 /// 
	\ hansenpercpassDFIinvdiffwpc1 \ hansenpercpassDFIinvlevwpc1 \ hansenpercpasspc1 \ condFDFIwpc1med ///
	\ condFDFIpercrejunderidwpc1 ///
	\ empty \ empty ///
	\ DFIinv2mean \ DFIinv2med \ DFIinv2sd \ pzeroaddpercreject2 \ pfulladdpercreject2 ///
	\ lagdep2mean \ lagdep2med \ lagdep2sd \ numinstr2 \ m1percpass2 ///
	\ m2percpass2 \ hansenpercpass2 \ sarganpercpass2 \ hansenpercpasslev2 \ hansenpercpasslagdep2 /// 
	\ hansenpercpassDFIinvdiff2 \ hansenpercpassDFIinvlev2 \ condFDFI2med ///
	\ condFDFIpercrejunderid2 ///
	\ empty ///
	\ DFIinvwpc2mean \ DFIinvwpc2med \ DFIinvwpc2sd \ pzeroaddpercrejectwpc2 \ pfulladdpercrejectwpc2 ///
	\ lagdepwpc2mean \ lagdepwpc2med \ lagdepwpc2sd \ numinstrwpc2 \ m1percpasswpc2 ///
	\ m2percpasswpc2 \ hansenpercpasswpc2 \ sarganpercpasswpc2 \ hansenpercpasslevwpc2 \ hansenpercpasslagdepwpc2 /// 
	\ hansenpercpassDFIinvdiffwpc2 \ hansenpercpassDFIinvlevwpc2 \ hansenpercpasspc2 \ condFDFIwpc2med ///
	\ condFDFIpercrejunderidwpc2 ///
	\ empty \ empty ///
	\ DFIinv3mean \ DFIinv3med \ DFIinv3sd \ pzeroaddpercreject3 \ pfulladdpercreject3 ///
	\ lagdep3mean \ lagdep3med \ lagdep3sd \ numinstr3 \ m1percpass3 ///
	\ m2percpass3 \ hansenpercpass3 \ sarganpercpass3 \ hansenpercpasslev3 \ hansenpercpasslagdep3 /// 
	\ hansenpercpassDFIinvdiff3 \ hansenpercpassDFIinvlev3 \ condFDFI3med ///
	\ condFDFIpercrejunderid3 ///
	\ empty ///
	\ DFIinvwpc3mean \ DFIinvwpc3med \ DFIinvwpc3sd \ pzeroaddpercrejectwpc3 \ pfulladdpercrejectwpc3 ///
	\ lagdepwpc3mean \ lagdepwpc3med \ lagdepwpc3sd \ numinstrwpc3 \ m1percpasswpc3 ///
	\ m2percpasswpc3 \ hansenpercpasswpc3 \ sarganpercpasswpc3 \ hansenpercpasslevwpc3 \ hansenpercpasslagdepwpc3 /// 
	\ hansenpercpassDFIinvdiffwpc3 \ hansenpercpassDFIinvlevwpc3 \ hansenpercpasspc3 \ condFDFIwpc3med ///
	\ condFDFIpercrejunderidwpc3 ///
	\ empty \ empty ///
	\ DFIinv4mean \ DFIinv4med \ DFIinv4sd \ pzeroaddpercreject4 \ pfulladdpercreject4 ///
	\ lagdep4mean \ lagdep4med \ lagdep4sd \ numinstr4 \ m1percpass4 ///
	\ m2percpass4 \ hansenpercpass4 \ sarganpercpass4 \ hansenpercpasslev4 \ hansenpercpasslagdep4 /// 
	\ hansenpercpassDFIinvdiff4 \ hansenpercpassDFIinvlev4 \ condFDFI4med ///
	\ condFDFIpercrejunderid4 ///
	\ empty ///
	\ DFIinvwpc4mean \ DFIinvwpc4med \ DFIinvwpc4sd \ pzeroaddpercrejectwpc4 \ pfulladdpercrejectwpc4 ///
	\ lagdepwpc4mean \ lagdepwpc4med \ lagdepwpc4sd \ numinstrwpc4 \ m1percpasswpc4 ///
	\ m2percpasswpc4 \ hansenpercpasswpc4 \ sarganpercpasswpc4 \ hansenpercpasslevwpc4 \ hansenpercpasslagdepwpc4 /// 
	\ hansenpercpassDFIinvdiffwpc4 \ hansenpercpassDFIinvlevwpc4 \ hansenpercpasspc4 \ condFDFIwpc4med ///
	\ condFDFIpercrejunderidwpc4 ///
	\ empty \ empty ///
	\ DFIinv5mean \ DFIinv5med \ DFIinv5sd \ pzeroaddpercreject5 \ pfulladdpercreject5 ///
	\ lagdep5mean \ lagdep5med \ lagdep5sd \ numinstr5 \ m1percpass5 ///
	\ m2percpass5 \ hansenpercpass5 \ sarganpercpass5 \ hansenpercpasslev5 \ hansenpercpasslagdep5 /// 
	\ hansenpercpassDFIinvdiff5 \ hansenpercpassDFIinvlev5 \ condFDFI5med ///
	\ condFDFIpercrejunderid5 ///
	\ empty ///
	\ DFIinvwpc5mean \ DFIinvwpc5med \ DFIinvwpc5sd \ pzeroaddpercrejectwpc5 \ pfulladdpercrejectwpc5 ///
	\ lagdepwpc5mean \ lagdepwpc5med \ lagdepwpc5sd \ numinstrwpc5 \ m1percpasswpc5 ///
	\ m2percpasswpc5 \ hansenpercpasswpc5 \ sarganpercpasswpc5 \ hansenpercpasslevwpc5 \ hansenpercpasslagdepwpc5 /// 
	\ hansenpercpassDFIinvdiffwpc5 \ hansenpercpassDFIinvlevwpc5 \ hansenpercpasspc5 \ condFDFIwpc5med ///
	\ condFDFIpercrejunderidwpc5 ///
	\ empty \ empty)

	
	matrix GMMfulladd_`num' = (GMMfulladd_`num' \ DFIinv6mean \ DFIinv6med \ DFIinv6sd \ pzeroaddpercreject6 \ pfulladdpercreject6 \ FSrobF6med ///
	\ FSbetaL2DFI6med \ OVbetaL2DFI6med \ corrL2DFIu6med \ corrL2DFIx6med \ sdu6med \ sdx6med \ DFIbiasDFIinv6mean \ DFIbiasDFIinv6med ///
	\ empty ///
	\ DFIinvwpc6mean \ DFIinvwpc6med \ DFIinvwpc6sd \ pzeroaddpercrejectwpc6 \ pfulladdpercrejectwpc6 \ FSrobFwpc6med ///
	\ FSbetaL2DFIwpc6med \ FSbetaL2pc6med \ OVbetaL2DFIwpc6med \ OVbetaL2pc6med /// 
	\ empty \ empty ///
	\ DFIinv7mean \ DFIinv7med \ DFIinv7sd \ pzeroaddpercreject7 \ pfulladdpercreject7 ///
	\ lagdep7mean \ lagdep7med \ lagdep7sd \ numinstr7 \ m1percpass7 ///
	\ m2percpass7 \ hansenpercpass7 \ sarganpercpass7 \ hansenpercpasslev7 \ hansenpercpasslagdep7 /// 
	\ hansenpercpassDFIinvdiff7 \ hansenpercpassDFIinvlev7 \ condFDFI7med ///
	\ condFDFIpercrejunderid7 ///
	\ empty ///
	\ DFIinvwpc7mean \ DFIinvwpc7med \ DFIinvwpc7sd \ pzeroaddpercrejectwpc7 \ pfulladdpercrejectwpc7 ///
	\ lagdepwpc7mean \ lagdepwpc7med \ lagdepwpc7sd \ numinstrwpc7 \ m1percpasswpc7 ///
	\ m2percpasswpc7 \ hansenpercpasswpc7 \ sarganpercpasswpc7 \ hansenpercpasslevwpc7 \ hansenpercpasslagdepwpc7 /// 
	\ hansenpercpassDFIinvdiffwpc7 \ hansenpercpassDFIinvlevwpc7 \ hansenpercpasspc7 \ condFDFIwpc7med ///
	\ condFDFIpercrejunderidwpc7 ///
	\ empty \ empty ///
	\ DFIinv8mean \ DFIinv8med \ DFIinv8sd \ pzeroaddpercreject8 \ pfulladdpercreject8 \ FSrobF8med ///
	\ FSbetaDLDFI8med \ OVbetaDLDFI8med \ corrDLDFIu8med \ corrDLDFIx8med \ sdu8med \ sdx8med ///
	\ DFIbiasDFIinv8mean \ DFIbiasDFIinv8med ///
	\ empty ///
	\ DFIinvwpc8mean \ DFIinvwpc8med \ DFIinvwpc8sd \ pzeroaddpercrejectwpc8 \ pfulladdpercrejectwpc8 \ FSrobFwpc8med ///
	\ FSbetaDLDFIwpc8med \ FSbetaDLpc8med \ OVbetaDLDFIwpc8med \ OVbetaDLpc8med /// 
	\ empty \ countmaxdbpercnumprojerover2exc1 \ successfulreps \ medmedinvDFIvsprivate)
	matrix list GMMfulladd_`num'
log close
} // close loop over generated datasets/experiments


/* Construct matrices that combine results. */
/* First table: */
foreach num of numlist 1/9 {
	if `num'==1 { 
		matrix tableGMMfulladd = GMMfulladd_`num'
	}
	else { 
		matrix tableGMMfulladd=(tableGMMfulladd, GMMfulladd_`num')
	}        
}


/* Export to Excel and clean up tables. */
/* First table: */
putexcel set "./Tables/GMMfulladdtable_", replace
putexcel B2 = matrix(tableGMMfulladd) // starting point of table
//
local row 3
//
putexcel A`row++' = "MODEL 1: SYSTEM GMM, STATIC MODEL, 1 LAG"
putexcel A`row++' = "WITHOUT PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "Lag dep coeff. mean"
putexcel A`row++' = "Lag dep coeff. median"
putexcel A`row++' = "Lag dep coeff. st. dev."
putexcel A`row++' = "# instruments"
putexcel A`row++' = "m1 % pass"
putexcel A`row++' = "m2 % pass"
putexcel A`row++' = "Hansen % pass"
putexcel A`row++' = "Sargan % pass"
putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
putexcel A`row++' = "Conditional F median"
putexcel A`row++' = "Conditional F % reject underidentification"
//
putexcel A`row++' = "WITH PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "Lag dep coeff. mean"
putexcel A`row++' = "Lag dep coeff. median"
putexcel A`row++' = "Lag dep coeff. st. dev."
putexcel A`row++' = "# instruments"
putexcel A`row++' = "m1 % pass"
putexcel A`row++' = "m2 % pass"
putexcel A`row++' = "Hansen % pass"
putexcel A`row++' = "Sargan % pass"
putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen pc % pass"
putexcel A`row++' = "Conditional F median"
putexcel A`row++' = "Conditional F % reject underidentification"
//
//
putexcel A`row++' = "MODEL 2: SYSTEM GMM, WITH LDV, 1 LAG"
putexcel A`row++' = "WITHOUT PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "Lag dep coeff. mean"
putexcel A`row++' = "Lag dep coeff. median"
putexcel A`row++' = "Lag dep coeff. st. dev."
putexcel A`row++' = "# instruments"
putexcel A`row++' = "m1 % pass"
putexcel A`row++' = "m2 % pass"
putexcel A`row++' = "Hansen % pass"
putexcel A`row++' = "Sargan % pass"
putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
putexcel A`row++' = "Conditional F median"
putexcel A`row++' = "Conditional F % reject underidentification"
//
putexcel A`row++' = "WITH PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "Lag dep coeff. mean"
putexcel A`row++' = "Lag dep coeff. median"
putexcel A`row++' = "Lag dep coeff. st. dev."
putexcel A`row++' = "# instruments"
putexcel A`row++' = "m1 % pass"
putexcel A`row++' = "m2 % pass"
putexcel A`row++' = "Hansen % pass"
putexcel A`row++' = "Sargan % pass"
putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen pc % pass"
putexcel A`row++' = "Conditional F median"
putexcel A`row++' = "Conditional F % reject underidentification"
//
//
putexcel A`row++' = "MODEL 3: SYSTEM GMM, STATIC MODEL, 4 LAGS"
putexcel A`row++' = "WITHOUT PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "Lag dep coeff. mean"
putexcel A`row++' = "Lag dep coeff. median"
putexcel A`row++' = "Lag dep coeff. st. dev."
putexcel A`row++' = "# instruments"
putexcel A`row++' = "m1 % pass"
putexcel A`row++' = "m2 % pass"
putexcel A`row++' = "Hansen % pass"
putexcel A`row++' = "Sargan % pass"
putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
putexcel A`row++' = "Conditional F median"
putexcel A`row++' = "Conditional F % reject underidentification"
//
putexcel A`row++' = "WITH PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "Lag dep coeff. mean"
putexcel A`row++' = "Lag dep coeff. median"
putexcel A`row++' = "Lag dep coeff. st. dev."
putexcel A`row++' = "# instruments"
putexcel A`row++' = "m1 % pass"
putexcel A`row++' = "m2 % pass"
putexcel A`row++' = "Hansen % pass"
putexcel A`row++' = "Sargan % pass"
putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen pc % pass"
putexcel A`row++' = "Conditional F median"
putexcel A`row++' = "Conditional F % reject underidentification"
//
//
putexcel A`row++' = "MODEL 4: SYSTEM GMM, WITH LDV, 4 LAGS"
putexcel A`row++' = "WITHOUT PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "Lag dep coeff. mean"
putexcel A`row++' = "Lag dep coeff. median"
putexcel A`row++' = "Lag dep coeff. st. dev."
putexcel A`row++' = "# instruments"
putexcel A`row++' = "m1 % pass"
putexcel A`row++' = "m2 % pass"
putexcel A`row++' = "Hansen % pass"
putexcel A`row++' = "Sargan % pass"
putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
putexcel A`row++' = "Conditional F median"
putexcel A`row++' = "Conditional F % reject underidentification"
//
putexcel A`row++' = "WITH PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "Lag dep coeff. mean"
putexcel A`row++' = "Lag dep coeff. median"
putexcel A`row++' = "Lag dep coeff. st. dev."
putexcel A`row++' = "# instruments"
putexcel A`row++' = "m1 % pass"
putexcel A`row++' = "m2 % pass"
putexcel A`row++' = "Hansen % pass"
putexcel A`row++' = "Sargan % pass"
putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen pc % pass"
putexcel A`row++' = "Conditional F median"
putexcel A`row++' = "Conditional F % reject underidentification"
//
//
putexcel A`row++' = "MODEL 5: DIFFERENCE GMM, STATIC MODEL, 1 LAG"
putexcel A`row++' = "WITHOUT PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "Lag dep coeff. mean"
putexcel A`row++' = "Lag dep coeff. median"
putexcel A`row++' = "Lag dep coeff. st. dev."
putexcel A`row++' = "# instruments"
putexcel A`row++' = "m1 % pass"
putexcel A`row++' = "m2 % pass"
putexcel A`row++' = "Hansen % pass"
putexcel A`row++' = "Sargan % pass"
putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
putexcel A`row++' = "Conditional F median"
putexcel A`row++' = "Conditional F % reject underidentification"
//
putexcel A`row++' = "WITH PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "Lag dep coeff. mean"
putexcel A`row++' = "Lag dep coeff. median"
putexcel A`row++' = "Lag dep coeff. st. dev."
putexcel A`row++' = "# instruments"
putexcel A`row++' = "m1 % pass"
putexcel A`row++' = "m2 % pass"
putexcel A`row++' = "Hansen % pass"
putexcel A`row++' = "Sargan % pass"
putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen pc % pass"
putexcel A`row++' = "Conditional F median"
putexcel A`row++' = "Conditional F % reject underidentification"
//
//
putexcel A`row++' = "MODEL 6: IV ON DIFFERENCED EQN., STATIC MODEL, 1 LAG"
putexcel A`row++' = "WITHOUT PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "FS robust F median"
putexcel A`row++' = "FS coeff. L2 DFI inv. median"
putexcel A`row++' = "OV coeff. L2 DFI inv. median"
putexcel A`row++' = "Corr(L2 DFI inv.,du) median"
putexcel A`row++' = "Corr(L2 DFI inv.,dx) median"
putexcel A`row++' = "St. dev. du median"
putexcel A`row++' = "St. dev. dx median"
putexcel A`row++' = "Mean bias based on DFI inv. instr."
putexcel A`row++' = "Median bias based on DFI inv. instr."
//
putexcel A`row++' = "WITH PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "FS robust F median"
putexcel A`row++' = "FS coeff. L2 DFI inv. median"
putexcel A`row++' = "FS coeff. L2 pc median"
putexcel A`row++' = "OV coeff. L2 DFI inv. median"
putexcel A`row++' = "OV coeff. L2 pc median"
//
//
putexcel A`row++' = "MODEL 7: LEVELS GMM, STATIC MODEL, 1 LAG"
putexcel A`row++' = "WITHOUT PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "Lag dep coeff. mean"
putexcel A`row++' = "Lag dep coeff. median"
putexcel A`row++' = "Lag dep coeff. st. dev."
putexcel A`row++' = "# instruments"
putexcel A`row++' = "m1 % pass"
putexcel A`row++' = "m2 % pass"
putexcel A`row++' = "Hansen % pass"
putexcel A`row++' = "Sargan % pass"
putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
putexcel A`row++' = "Conditional F median"
putexcel A`row++' = "Conditional F % reject underidentification"
//
putexcel A`row++' = "WITH PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "Lag dep coeff. mean"
putexcel A`row++' = "Lag dep coeff. median"
putexcel A`row++' = "Lag dep coeff. st. dev."
putexcel A`row++' = "# instruments"
putexcel A`row++' = "m1 % pass"
putexcel A`row++' = "m2 % pass"
putexcel A`row++' = "Hansen % pass"
putexcel A`row++' = "Sargan % pass"
putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen pc % pass"
putexcel A`row++' = "Conditional F median"
putexcel A`row++' = "Conditional F % reject underidentification"
//
//
putexcel A`row++' = "MODEL 8: IV ON LEVELS EQN, STATIC MODEL, 1 LAG"
putexcel A`row++' = "WITHOUT PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "FS robust F median"
putexcel A`row++' = "FS coeff. DL DFI inv. median"
putexcel A`row++' = "OV coeff. DL DFI inv. median"
putexcel A`row++' = "Corr(DL DFI inv.,u) median"
putexcel A`row++' = "Corr(DL DFI inv.,x) median"
putexcel A`row++' = "St. dev. u median"
putexcel A`row++' = "St. dev. x median"
putexcel A`row++' = "Mean bias based on DFI inv. instr."
putexcel A`row++' = "Median bias based on DFI inv. instr."
//
putexcel A`row++' = "WITH PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "FS robust F median"
putexcel A`row++' = "FS coeff. DL DFI inv. median"
putexcel A`row++' = "FS coeff. DL pc median"
putexcel A`row++' = "OV coeff. DL DFI inv. median"
putexcel A`row++' = "OV coeff. DL pc median"
//
putexcel A`row++' = " "
putexcel A`row++' = "Number of datasets where max db exceeds # proj. with er > 2"
putexcel A`row++' = "# successful replications"
putexcel A`row++' = "Med. of med. DFI inv/private"
//
putexcel B1= "No noise in pc"
putexcel C1= "Noise 0.5"
putexcel D1= "Noise 1"
putexcel E1= "pc mean closer, noise 0.5"
putexcel F1= "pc mean = 2, noise 0.5"
putexcel G1= "upward drift, noise 0.5"
putexcel H1= "fixed types, noise 0.5"
putexcel I1= "fixed types, upward drift, noise 0.5"
putexcel J1= "fixed types, downward drift, noise 0.5"


/* Now generate table to export to TeX, using texdoc. */
/* Baseline table. */
texdoc init "`tablesexport'/GMMexport_fulladd_.tex", replace force
tex  								  & \mcolsfe{(1)} 				      & \mcolsfe{(2)} 				         & \mcolsfe{(3)} 						 & \mcolsfe{(4)} 					    & \mcolsfe{(5)} 				    & \mcolsfe{(6)} 				       & \mcolsfe{(7)} 						   & \mcolsfe{(8)} \\
tex LDV                               & \mcolsfe{no}                      & \mcolsfe{no}                         & \mcolsfe{no}                          & \mcolsfe{no}                         & \mcolsfe{yes}                     & \mcolsfe{yes}                        & \mcolsfe{yes}                         & \mcolsfe{yes} \\
tex $\mathit{pc}$                     & \mcolsfe{excl.}                   & \mcolsfe{$\sigma_m^{2} = 1$}         & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}} & \mcolsfe{$\sigma_m^{2} = 0$}         & \mcolsfe{excl.}                   & \mcolsfe{$\sigma_m^{2} = 1$}         & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}} & \mcolsfe{$\sigma_m^{2} = 0$} \\
tex \cmidrule{1-9}
tex Med.\ $\widehat{\beta}_{sysGMM}$  & `sysGMM1betadfimedian1'           & `sysGMMwpc1betadfimedian3'           & `sysGMMwpc1betadfimedian2'            & `sysGMMwpc1betadfimedian1'           & `sysGMM2betadfimedian1'           & `sysGMMwpc2betadfimedian3'           & `sysGMMwpc2betadfimedian2'            & `sysGMMwpc2betadfimedian1' \\
tex Std.\ dev.\	                      & `sysGMM1betadfisd1'               & `sysGMMwpc1betadfisd3'               & `sysGMMwpc1betadfisd2'                & `sysGMMwpc1betadfisd1'               & `sysGMM2betadfisd1'               & `sysGMMwpc2betadfisd3'               & `sysGMMwpc2betadfisd2'                & `sysGMMwpc2betadfisd1' \\
tex \% reject $\beta \geqslant 1$     & \mcc{`sysGMMfulladdpercreject11'} & \mcc{`sysGMMfulladdpercrejectwpc13'} & \mcc{`sysGMMfulladdpercrejectwpc12'}  & \mcc{`sysGMMfulladdpercrejectwpc11'} & \mcc{`sysGMMfulladdpercreject21'} & \mcc{`sysGMMfulladdpercrejectwpc23'} & \mcc{`sysGMMfulladdpercrejectwpc22'}  & \mcc{`sysGMMfulladdpercrejectwpc21'} \\
tex Hansen \% pass                    & \mcc{`sysGMMhansenpercpass11'}    & \mcc{`sysGMMhansenpercpasswpc13'}    & \mcc{`sysGMMhansenpercpasswpc12'}     & \mcc{`sysGMMhansenpercpasswpc11'}    & \mcc{`sysGMMhansenpercpass21'}    & \mcc{`sysGMMhansenpercpasswpc23'}    & \mcc{`sysGMMhansenpercpasswpc22'}     & \mcc{`sysGMMhansenpercpasswpc21'} \\
tex Med.\ cond.\ F                    & \mcc{`sysGMMcondFDFI1med1'}       & \mcc{`sysGMMcondFDFIwpc1med3'}       & \mcc{`sysGMMcondFDFIwpc1med2'}        & \mcc{`sysGMMcondFDFIwpc1med1'}       & \mcc{`sysGMMcondFDFI2med1'}       & \mcc{`sysGMMcondFDFIwpc2med3'}       & \mcc{`sysGMMcondFDFIwpc2med2'}        & \mcc{`sysGMMcondFDFIwpc2med1'} \\
tex \mbox{\% reject underid.}         & \mcc{`sysGMMcondFDFIpercrej11'}   & \mcc{`sysGMMcondFDFIpercrejwpc13'}   & \mcc{`sysGMMcondFDFIpercrejwpc12'}    & \mcc{`sysGMMcondFDFIpercrejwpc11'}   & \mcc{`sysGMMcondFDFIpercrej21'}   & \mcc{`sysGMMcondFDFIpercrejwpc23'}   & \mcc{`sysGMMcondFDFIpercrejwpc22'}    & \mcc{`sysGMMcondFDFIpercrejwpc21'} \\
tex \bottomrule
texdoc close


/* Additional experiments. */
texdoc init "`tablesexport'/GMMexport_fulladd_2_.tex", replace force
tex  								  & \mcolsfe{(1)} 				      & \mcolsfe{(2)} 				                                    & \mcolsfe{(3)} 				    & \mcolsfe{(4)} 					                           & \mcolsfe{(5)} 				       & \mcolsfe{(6)} 				                           & \mcolsfe{(7)} 						 & \mcolsfe{(8)} \\
tex Experiment description            & \multicolumn{2}{c}{\begin{tabular}{@{}c@{}}Upward trend \tabularnewline in DFI budget\end{tabular}} & \multicolumn{2}{c}{\begin{tabular}{@{}c@{}}$\mu_c$ closer \tabularnewline together\end{tabular}} & \multicolumn{2}{c}{\begin{tabular}{@{}c@{}}$\mu_c$ the \tabularnewline same\end{tabular}} &  \multicolumn{2}{c}{\begin{tabular}{@{}c@{}}Upward trend \tabularnewline in DFI budget, \tabularnewline fixed types\end{tabular}} \\
tex $\mathit{pc}$                     & \mcolsfe{excl.}                   & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}}                           & \mcolsfe{excl.}                   & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}}                        & \mcolsfe{excl.}                   & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}}                 & \mcolsfe{excl.}                     & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}} \\
tex $\sigma_{db}$                     & \mcc{0}                           & \mcc{0}                                                         & \mcc{0.15}                        & \mcc{0.15}                                                   & \mcc{0.15}                        & \mcc{0.15}                                            & \mcc{0}                             & \mcc{0} \\
tex $\mathit{drift}$                  & \mcc{0.05}                        & \mcc{0.05}                                                      & \mcc{0}                           & \mcc{0}                                                      & \mcc{0}                           & \mcc{0}                                               & \mcc{0.05}                          & \mcc{0.05} \\
tex $\mu_c$                           & \mcc{$\left[0, 2, 4\right]$}      & \mcc{$\left[0, 2, 4\right]$}                                    & \mcc{$\left[1, 2, 3\right]$}      & \mcc{$\left[1, 2, 3\right]$}                                 & \mcc{$\left[2, 2, 2\right]$}      & \mcc{$\left[2, 2, 2\right]$}                          & \mcc{$\left[0, 2, 4\right]$}        & \mcc{$\left[0, 2, 4\right]$} \\
tex $\Delta$ types                    & \mcolsfe{default}                 & \mcolsfe{default}                                               & \mcolsfe{default}                 & \mcolsfe{default}                                            & \mcolsfe{default}                 & \mcolsfe{default}                                     & \mcolsfe{fixed}                     & \mcolsfe{fixed} \\
tex \cmidrule{1-9}                                                                  
tex Med.\ $\widehat{\beta}_{sysGMM}$  & `sysGMM1betadfimedian6'           & `sysGMMwpc1betadfimedian6'                                      & `sysGMM1betadfimedian4'           & `sysGMMwpc1betadfimedian4'                                   & `sysGMM1betadfimedian5'           & `sysGMMwpc1betadfimedian5'                            & `sysGMM1betadfimedian8'            & `sysGMMwpc1betadfimedian8' \\
tex Std.\ dev.\	                      & `sysGMM1betadfisd6'               & `sysGMMwpc1betadfisd6'                                          & `sysGMM1betadfisd4'               & `sysGMMwpc1betadfisd4'                                       & `sysGMM1betadfisd5'               & `sysGMMwpc1betadfisd5'                                & `sysGMM1betadfisd8'                & `sysGMMwpc1betadfisd8' \\
tex \% reject $\beta \geqslant 1$     & \mcc{`sysGMMfulladdpercreject16'} & \mcc{`sysGMMfulladdpercrejectwpc16'}                            & \mcc{`sysGMMfulladdpercreject14'} & \mcc{`sysGMMfulladdpercrejectwpc14'}                         & \mcc{`sysGMMfulladdpercreject15'} & \mcc{`sysGMMfulladdpercrejectwpc15'}                  & \mcc{`sysGMMfulladdpercreject18'}  & \mcc{`sysGMMfulladdpercrejectwpc18'} \\
tex Hansen \% pass                    & \mcc{`sysGMMhansenpercpass16'}    & \mcc{`sysGMMhansenpercpasswpc16'}                               & \mcc{`sysGMMhansenpercpass14'}    & \mcc{`sysGMMhansenpercpasswpc14'}                            & \mcc{`sysGMMhansenpercpass15'}    & \mcc{`sysGMMhansenpercpasswpc15'}                     & \mcc{`sysGMMhansenpercpass18'}     & \mcc{`sysGMMhansenpercpasswpc18'} \\
tex Med.\ cond.\ F                    & \mcc{`sysGMMcondFDFI1med6'}       & \mcc{`sysGMMcondFDFIwpc1med6'}                                  & \mcc{`sysGMMcondFDFI1med4'}       & \mcc{`sysGMMcondFDFIwpc1med4'}                               & \mcc{`sysGMMcondFDFI1med5'}       & \mcc{`sysGMMcondFDFIwpc1med5'}                        & \mcc{`sysGMMcondFDFI1med8'}        & \mcc{`sysGMMcondFDFIwpc1med8'} \\
tex \mbox{\% reject underid.}         & \mcc{`sysGMMcondFDFIpercrej16'}   & \mcc{`sysGMMcondFDFIpercrejwpc16'}                              & \mcc{`sysGMMcondFDFIpercrej14'}   & \mcc{`sysGMMcondFDFIpercrejwpc14'}                           & \mcc{`sysGMMcondFDFIpercrej15'}   & \mcc{`sysGMMcondFDFIpercrejwpc15'}                    & \mcc{`sysGMMcondFDFIpercrej18'}    & \mcc{`sysGMMcondFDFIpercrejwpc18'} \\
tex Med.\ $\widehat{\beta}_{diffGMM}$ & `sysGMM5betadfimedian6'           & `sysGMMwpc5betadfimedian6'                                      & `sysGMM5betadfimedian4'           & `sysGMMwpc5betadfimedian4'                                   & `sysGMM5betadfimedian5'           & `sysGMMwpc5betadfimedian5'                            & `sysGMM5betadfimedian8'            & `sysGMMwpc5betadfimedian8' \\
tex Med.\ $\widehat{\beta}_{levGMM}$  & `sysGMM7betadfimedian6'           & `sysGMMwpc7betadfimedian6'                                      & `sysGMM7betadfimedian4'           & `sysGMMwpc7betadfimedian4'                                   & `sysGMM7betadfimedian5'           & `sysGMMwpc7betadfimedian5'                            & `sysGMM7betadfimedian8'            & `sysGMMwpc7betadfimedian8' \\	
tex \bottomrule
texdoc close


*************************************************************************
* SUPPLY-PUSH IV WITH ZERO ADDITIONALITY
*************************************************************************
foreach option in exclhighdb "" { // exclhighdb drops replications where DFI sector budget exceeds # projects with er > 2 in at least one year.
	foreach num of numlist 1/14 {
		clear
		capture log close
		log using "./Generated data/IVzeroadd`num'", replace text
		use "./Generated data/IVzeroadd`num'.dta"


		if "`option'" == "exclhighdb" {
			drop if maxdbpercnumprojerover2 >= 1 & maxdbpercnumprojerover2 != .
		}
		else if "`option'" == "" {
			// do nothing
		}
		else {
			di as error "Local option not specified correctly"
		}


		/* First check if all replications have been successful. */
		egen nummissing = rowmiss(ivbetadfi-type3dfiinvIVy20)
		tab nummissing, missing
		count if nummissing == 0
		scalar successfulreps = r(N)
		foreach var of varlist * { 
			replace `var' = . if nummissing != 0
		}
	
			
		/* Now pick up selected IV statistics to export to Excel later: */
		su ivbetadfi, detail
		scalar IVbetadfimean=r(mean)
		scalar IVbetadfimedian=r(p50)
		local IVbetadfimedian`num': di %4.2f IVbetadfimedian				
		scalar IVbetadfisd=r(sd)
		local IVbetadfisd`num': di %4.2f IVbetadfisd							
		su febetadfi, detail
		scalar FEbetadfimean=r(mean)
		scalar FEbetadfimedian=r(p50)
		su ivbetadfil1out, detail
		scalar IVbetadfil1outmedian=r(p50)
		local IVbetadfimedianl1out`num': di %4.2f IVbetadfil1outmedian				
		scalar IVbetadfil1outsd=r(sd)
		local IVbetadfil1outsd`num': di %4.2f IVbetadfil1outsd							
		su ivbetadfict, detail
		scalar IVbetadfictmedian=r(p50)
		local IVbetadfictmedian`num': di %4.2f IVbetadfictmedian				
		scalar IVbetadfictsd=r(sd)
		local IVbetadfictsd`num': di %4.2f IVbetadfictsd							
		//
		su ivpcbetadfi, detail
		scalar IVpcbetadfimean=r(mean)
		scalar IVpcbetadfimedian=r(p50)
		local IVpcbetadfimedian`num': di %4.2f IVpcbetadfimedian				
		scalar IVpcbetadfisd=r(sd)
		local IVpcbetadfisd`num': di %4.2f IVpcbetadfisd						
		su fepcbetadfi, detail
		scalar FEpcbetadfimean=r(mean)
		scalar FEpcbetadfimedian=r(p50)
		su ivpcbetadfil1out, detail
		scalar IVpcbetadfil1outmedian=r(p50)
		//		
		count if ivpzeroadd < 0.05
		scalar IVzeroaddpercreject=(r(N)/successfulreps)*100
		local IVzeroaddpercreject`num': di %5.0g IVzeroaddpercreject
		count if ivpzeroaddl1out < 0.05
		scalar IVzeroaddpercrejectl1out=(r(N)/successfulreps)*100
		local IVzeroaddpercrejectl1out`num': di %5.0g IVzeroaddpercrejectl1out
		count if ivpzeroaddct < 0.05
		scalar IVzeroaddpercrejectct=(r(N)/successfulreps)*100
		local IVzeroaddpercrejectct`num': di %5.0g IVzeroaddpercrejectct
		//
		count if ivpcpzeroadd < 0.05
		scalar IVpczeroaddpercreject=(r(N)/successfulreps)*100
		local IVpczeroaddpercreject`num': di %5.0g IVpczeroaddpercreject
		count if ivpcpzeroaddl1out < 0.05
		scalar IVpczeroaddpercrejectl1out=(r(N)/successfulreps)*100
		//
		su weakid, detail
		scalar IVmedFSF=r(p50)
		local IVmedFSF`num': di %5.0g IVmedFSF
		scalar IVminFSF=r(min)
		count if weakid > 10 & weakid != .
		scalar IVFSFpercover10=(r(N)/successfulreps)*100
		su weakidl1out, detail
		scalar IVmedFSFl1out=r(p50)
		local IVmedFSFl1out`num': di %5.0g IVmedFSFl1out
		su weakidct, detail
		scalar IVmedFSFct=r(p50)
		local IVmedFSFct`num': di %5.0g IVmedFSFct
		su underid, detail
		scalar IVmedFSLM=r(p50)
		scalar IVminFSLM=r(min)
		count if underid > 10 & underid != .
		scalar IVFSLMpercover10=(r(N)/successfulreps)*100
		su underidl1out, detail
		scalar IVmedFSLMl1out=r(p50)
		su underidct, detail
		scalar IVmedFSLMct=r(p50)
		count if underidp < 0.05
		scalar IVunderidpercreject=(r(N)/successfulreps)*100
		local IVunderidpercreject`num': di %5.0g IVunderidpercreject
		count if underidpl1out < 0.05
		scalar IVunderidpercrejectl1out=(r(N)/successfulreps)*100	
		local IVunderidpercrejectl1out`num': di %5.0g IVunderidpercrejectl1out
		count if underidpct < 0.05
		scalar IVunderidpercrejectct=(r(N)/successfulreps)*100	
		local IVunderidpercrejectct`num': di %5.0g IVunderidpercrejectct
		//
		su weakidpc, detail
		scalar IVpcmedFSF=r(p50)
		local IVpcmedFSF`num': di %5.0g IVpcmedFSF
		scalar IVpcminFSF=r(min)
		count if weakidpc > 10 & weakidpc != .
		scalar IVpcFSFpercover10=(r(N)/successfulreps)*100
		su weakidpcl1out, detail
		scalar IVpcmedFSFl1out=r(p50)
		su underidpc, detail
		scalar IVpcmedFSLM=r(p50)
		scalar IVpcminFSLM=r(min)
		count if underidpc > 10 & underidpc != .
		scalar IVpcFSLMpercover10=(r(N)/successfulreps)*100
		su underidpcl1out, detail
		scalar IVpcmedFSLMl1out=r(p50)
		count if underidppc < 0.05
		scalar IVpcunderidpercreject=(r(N)/successfulreps)*100
		local IVpcunderidpercreject`num': di %5.0g IVpcunderidpercreject
		count if underidppcl1out < 0.05
		scalar IVpcunderidpercrejectl1out=(r(N)/successfulreps)*100	
		//
		su ivFSbeta, detail
		scalar IVbetaFSmean=r(mean)
		scalar IVbetaFSmedian=r(p50)
		scalar IVbetaFSsd=r(sd)
		local IVbetaFSmedian`num': di %4.2f IVbetaFSmedian				
		su ivRFbeta, detail
		scalar IVbetaRFmean=r(mean)
		scalar IVbetaRFmedian=r(p50)
		scalar IVbetaRFsd=r(sd)
		local IVbetaRFmedian`num': di %4.2f IVbetaRFmedian				
		su ivFSbetact, detail
		scalar IVbetactFSmean=r(mean)
		scalar IVbetactFSmedian=r(p50)
		scalar IVbetactFSsd=r(sd)
		local IVbetactFSmedian`num': di %4.2f IVbetactFSmedian				
		su ivRFbetact, detail
		scalar IVbetactRFmean=r(mean)
		scalar IVbetactRFmedian=r(p50)
		scalar IVbetactRFsd=r(sd)
		local IVbetactRFmedian`num': di %4.2f IVbetactRFmedian				
		//
		su ivpcFSbeta, detail
		scalar IVpcbetaFSmean=r(mean)
		scalar IVpcbetaFSmedian=r(p50)
		scalar IVpcbetaFSsd=r(sd)
		local IVpcbetaFSmedian`num': di %4.2f IVpcbetaFSmedian				
		su ivpcRFbeta, detail
		scalar IVpcbetaRFmean=r(mean)
		scalar IVpcbetaRFmedian=r(p50)
		scalar IVpcbetaRFsd=r(sd)
		local IVpcbetaRFmedian`num': di %4.2f IVpcbetaRFmedian				

		
		/* Bias in IV */
		su ivbetadfitrue, detail
		scalar IVbetadfitruemean = r(mean)
		su ivbetanumprojerover2, detail
		scalar IVbetanumprojerover2mean = r(mean)
		// with pc
		su ivpcbetadfitrue, detail
		scalar IVpcbetadfitruemean = r(mean)
		su ivpcbetanumprojerover2, detail
		scalar IVpcbetanumprojerover2mean = r(mean)
		su ivpcbetapctrue, detail
		scalar IVpcbetapctruemean = r(mean)
		//
		gen double bias = covzu/covzx
		su bias, detail
		scalar IVbiasdfimean = r(mean)
		scalar IVbiasdfimedian = r(p50)
		gen double bias2 = (corrzu/corrzx)*(sdu/sdx)
		su bias2, detail 
		scalar IVbias2dfimean = r(mean)
		scalar IVbias2dfimedian = r(p50)
		su covzu, detail
		scalar IVcovzumean = r(mean)
		scalar IVcovzumedian = r(p50)
		su covzx, detail
		scalar IVcovzxmean = r(mean)
		scalar IVcovzxmedian = r(p50)
		su varz, detail
		scalar IVvarzmean = r(mean)
		scalar IVvarzmedian = r(p50)
		su corrzu, detail
		scalar IVcorrzumean = r(mean)
		scalar IVcorrzumedian = r(p50)
		su corrzx, detail
		scalar IVcorrzxmean = r(mean)
		scalar IVcorrzxmedian = r(p50)
		su sdu, detail
		scalar IVsdumean = r(mean)
		scalar IVsdumedian = r(p50)
		su sdx, detail
		scalar IVsdxmean = r(mean)
		scalar IVsdxmedian = r(p50)
		//
		gen double pcbias = pccovzu/pccovzx
		su pcbias, detail
		scalar IVpcbiasdfimean = r(mean)
		scalar IVpcbiasdfimedian = r(p50)
		gen double pcbias2 = (pccorrzu/pccorrzx)*(pcsdu/pcsdx)
		su pcbias2, detail
		scalar IVpcbias2dfimean = r(mean)
		scalar IVpcbias2dfimedian = r(p50)
		su pccovzu, detail
		scalar IVpccovzumean = r(mean)
		scalar IVpccovzumedian = r(p50)
		su pccovzx, detail
		scalar IVpccovzxmean = r(mean)
		scalar IVpccovzxmedian = r(p50)
		su pcvarz, detail
		scalar IVpcvarzmean = r(mean)
		scalar IVpcvarzmedian = r(p50)
		su pccorrzu, detail
		scalar IVpccorrzumean = r(mean)
		scalar IVpccorrzumedian = r(p50)
		su pccorrzx, detail
		scalar IVpccorrzxmean = r(mean)
		scalar IVpccorrzxmedian = r(p50)
		su pcsdu, detail
		scalar IVpcsdumean = r(mean)
		scalar IVpcsdumedian = r(p50)
		su pcsdx, detail
		scalar IVpcsdxmean = r(mean)
		scalar IVpcsdxmedian = r(p50)
		
		
		/* Evolution of variables by type */
		foreach var of varlist type1invy1-type3dfiinvIVy20 {
			su `var', detail
			scalar `var'med = r(p50)
		}

		
		count if maxdbpercnumprojerover2 >= 1 & maxdbpercnumprojerover2 != .
		scalar countmaxdbpercnumprojerover2exc1 = r(N)

		su medinvDFIvsprivate, detail
		scalar medmedinvDFIvsprivate = r(p50)
				
		scalar empty = .
		scalar number = `num'

		
		// Put statistics in matrix:
		matrix IVzeroadd_`num' = (number \ IVbetadfimean \ IVbetadfimedian \ IVbetadfisd \ IVzeroaddpercreject /// 
		\ IVmedFSF \ IVminFSF \ IVFSFpercover10 \ IVmedFSLM \ IVminFSLM \ IVFSLMpercover10 \ IVunderidpercreject ///
		\ IVbetaFSmean \ IVbetaFSmedian \ IVbetaFSsd \ IVbetaRFmean \ IVbetaRFmedian \ IVbetaRFsd \ FEbetadfimean \ FEbetadfimedian ///
		\ IVbetadfil1outmedian \ IVzeroaddpercrejectl1out /// 
		\ IVmedFSFl1out \ IVmedFSLMl1out \ IVunderidpercrejectl1out ///
		\ IVbetadfictmedian \ IVzeroaddpercrejectct /// 
		\ IVmedFSFct \ IVmedFSLMct \ IVunderidpercrejectct ///
		\ IVbetactFSmean \ IVbetactFSmedian \ IVbetactFSsd \ IVbetactRFmean \ IVbetactRFmedian \ IVbetactRFsd ///
		\ IVbetadfitruemean \ IVbetanumprojerover2mean \ IVbiasdfimean \ IVcovzumean \ IVcovzxmean \ IVvarzmean \ IVbias2dfimean \ IVcorrzumean \ IVcorrzxmean \ IVsdumean \ IVsdxmean ///
		\ IVbiasdfimedian \ IVcovzumedian \ IVcovzxmedian \ IVvarzmedian \ IVbias2dfimedian \ IVcorrzumedian \ IVcorrzxmedian \ IVsdumedian \ IVsdxmedian \ empty ///
		\ type1invy1med \ type1invy20med \ type2invy1med \ type2invy20med \ type3invy1med \ type3invy20med ///
	    \ type1dfiinvy1med \ type1dfiinvy20med \ type2dfiinvy1med \ type2dfiinvy20med \ type3dfiinvy1med \ type3dfiinvy20med ///
		\ type1dfiinvIVy1med \ type1dfiinvIVy20med \ type2dfiinvIVy1med \ type2dfiinvIVy20med \ type3dfiinvIVy1med \ type3dfiinvIVy20med \ empty /// 
		\ IVpcbetadfimean \ IVpcbetadfimedian \ IVpcbetadfisd \ IVpczeroaddpercreject ///
		\ IVpcmedFSF \ IVpcminFSF \ IVpcFSFpercover10 \ IVpcmedFSLM \ IVpcminFSLM \ IVpcFSLMpercover10 \ IVpcunderidpercreject /// 
		\ IVpcbetaFSmean \ IVpcbetaFSmedian \ IVpcbetaFSsd \ IVpcbetaRFmean \ IVpcbetaRFmedian \ IVpcbetaRFsd \ FEpcbetadfimean \ FEpcbetadfimedian ///
		\ IVpcbetadfil1outmedian \ IVpczeroaddpercrejectl1out ///
		\ IVpcmedFSFl1out \ IVpcmedFSLMl1out \ IVpcunderidpercrejectl1out ///
		\ IVpcbetadfitruemean \ IVpcbetanumprojerover2mean \ IVpcbetapctruemean \ IVpcbiasdfimean \ IVpccovzumean \ IVpccovzxmean \ IVpcvarzmean /// 
		\ IVpcbias2dfimean \ IVpccorrzumean \ IVpccorrzxmean \ IVpcsdumean \ IVpcsdxmean /// 
		\ IVpcbiasdfimedian \ IVpccovzumedian \ IVpccovzxmedian \ IVpcvarzmedian \ IVpcbias2dfimedian /// 
		\ IVpccorrzumedian \ IVpccorrzxmedian \ IVpcsdumedian \ IVpcsdxmedian /// 
		\ empty \ countmaxdbpercnumprojerover2exc1 \ successfulreps \ medmedinvDFIvsprivate)
		matrix list IVzeroadd_`num'
		log close
	}
	



	/* Construct matrices that combine results. */
	foreach num of numlist 1/14 {
		if `num'==1 { 
			matrix tableIVzeroadd = IVzeroadd_`num'
		}
		else { 
			matrix tableIVzeroadd=(tableIVzeroadd, IVzeroadd_`num')
		}        
	}

	 
	/* Export to Excel and clean up tables. */
	putexcel set "./Tables/IVzeroaddtable_`option'", replace
	putexcel C2 = matrix(tableIVzeroadd) // starting point of table
	//
	putexcel A3 = "Without pc"
	putexcel A20 = "FE (no IV)"
	putexcel A22 = "Leave 1 out"
	putexcel A27 = "Country trend"
	putexcel A38 = "Analyse bias"
	putexcel A59 = "Evolution of types"
	putexcel A78 = "With pc"
	putexcel A95 = "FE (no IV)"
	putexcel A97 = "Leave 1 out"
	putexcel A103 = "Analyse bias"
	//
	local row 3
	putexcel B`row++' = "DFI coeff. mean"
	putexcel B`row++' = "DFI coeff. median"
	putexcel B`row++' = "DFI coeff. st. dev."
	putexcel B`row++' = "% reject zero additionality"
	putexcel B`row++' = "Median FS F"
	putexcel B`row++' = "Min. FS F"
	putexcel B`row++' = "% FS F > 10"
	putexcel B`row++' = "Median FS LM"
	putexcel B`row++' = "Min. FS LM"
	putexcel B`row++' = "% FS LM > 10"
	putexcel B`row++' = "% reject underidentification"
	putexcel B`row++' = "FS instr. coeff. mean"
	putexcel B`row++' = "FS instr. coeff. median"
	putexcel B`row++' = "FS instr. coeff. st. dev."
	putexcel B`row++' = "RF instr. coeff. mean"
	putexcel B`row++' = "RF instr. coeff. median"
	putexcel B`row++' = "RF instr. coeff. st. dev."
	putexcel B`row++' = "FE DFI coeff. mean"
	putexcel B`row++' = "FE DFI coeff. median"
	putexcel B`row++' = "DFI coeff. median leave 1 out"
	putexcel B`row++' = "% reject zero add. leave 1 out"
	putexcel B`row++' = "Median FS F leave 1 out"
	putexcel B`row++' = "Median FS LM leave 1 out"
	putexcel B`row++' = "% reject underid. leave 1 out"
	putexcel B`row++' = "DFI coeff. median country trend"
	putexcel B`row++' = "% reject zero add. country trend"
	putexcel B`row++' = "Median FS F country trend"
	putexcel B`row++' = "Median FS LM country trend"
	putexcel B`row++' = "% reject underid. country trend"
	putexcel B`row++' = "FS instr. coeff. mean"
	putexcel B`row++' = "FS instr. coeff. median"
	putexcel B`row++' = "FS instr. coeff. st. dev."
	putexcel B`row++' = "RF instr. coeff. mean"
	putexcel B`row++' = "RF instr. coeff. median"
	putexcel B`row++' = "RF instr. coeff. st. dev."
	putexcel B`row++' = "DFI coeff. mean in true model"
	putexcel B`row++' = "# projects er > 2 coeff. mean"
	putexcel B`row++' = "DFI coeff. bias mean"
	putexcel B`row++' = "Cov(z,u) mean"
	putexcel B`row++' = "Cov(z,x) mean"
	putexcel B`row++' = "Var(z) mean"
	putexcel B`row++' = "DFI coeff. bias mean"
	putexcel B`row++' = "Corr(z,u) mean"
	putexcel B`row++' = "Corr(z,x) mean"
	putexcel B`row++' = "Sd(u) mean"
	putexcel B`row++' = "Sd(x) mean"
	putexcel B`row++' = "DFI coeff. bias median"
	putexcel B`row++' = "Cov(z,u) median"
	putexcel B`row++' = "Cov(z,x) median"
	putexcel B`row++' = "Var(z) median"
	putexcel B`row++' = "DFI coeff. bias median"
	putexcel B`row++' = "Corr(z,u) median"
	putexcel B`row++' = "Corr(z,x) median"
	putexcel B`row++' = "Sd(u) median"
	putexcel B`row++' = "Sd(x) median"
	putexcel B`row++' = " "
	putexcel B`row++' = "Type 1 median inv Y1"
	putexcel B`row++' = "Type 1 median inv Y20"
	putexcel B`row++' = "Type 2 median inv Y1"
	putexcel B`row++' = "Type 2 median inv Y20"
	putexcel B`row++' = "Type 3 median inv Y1"
	putexcel B`row++' = "Type 3 median inv Y20"
	putexcel B`row++' = "Type 1 median DFI inv Y1"
	putexcel B`row++' = "Type 1 median DFI inv Y20"
	putexcel B`row++' = "Type 2 median DFI inv Y1"
	putexcel B`row++' = "Type 2 median DFI inv Y20"
	putexcel B`row++' = "Type 3 median DFI inv Y1"
	putexcel B`row++' = "Type 3 median DFI inv Y20"
	putexcel B`row++' = "Type 1 median DFI inv IV Y1"
	putexcel B`row++' = "Type 1 median DFI inv IV Y20"
	putexcel B`row++' = "Type 2 median DFI inv IV Y1"
	putexcel B`row++' = "Type 2 median DFI inv IV Y20"
	putexcel B`row++' = "Type 3 median DFI inv IV Y1"
	putexcel B`row++' = "Type 3 median DFI inv IV Y20"
	//
	putexcel B`row++' = " "
	putexcel B`row++' = "DFI coeff. mean"
	putexcel B`row++' = "DFI coeff. median"
	putexcel B`row++' = "DFI coeff. st. dev."
	putexcel B`row++' = "% reject zero additionality"
	putexcel B`row++' = "Median FS F"
	putexcel B`row++' = "Min. FS F"
	putexcel B`row++' = "% FS F > 10"
	putexcel B`row++' = "Median FS LM"
	putexcel B`row++' = "Min. FS LM"
	putexcel B`row++' = "% FS LM > 10"
	putexcel B`row++' = "% reject underidentification"
	putexcel B`row++' = "FS instr. coeff. mean"
	putexcel B`row++' = "FS instr. coeff. median"
	putexcel B`row++' = "FS instr. coeff. st. dev."
	putexcel B`row++' = "RF instr. coeff. mean"
	putexcel B`row++' = "RF instr. coeff. median"
	putexcel B`row++' = "RF instr. coeff. st. dev."
	putexcel B`row++' = "FE DFI coeff. mean"
	putexcel B`row++' = "FE DFI coeff. median"
	putexcel B`row++' = "DFI coeff. median leave 1 out"
	putexcel B`row++' = "% reject zero add. leave 1 out"
	putexcel B`row++' = "Median FS F leave 1 out"
	putexcel B`row++' = "Median FS LM leave 1 out"
	putexcel B`row++' = "% reject underid. leave 1 out"
	putexcel B`row++' = "DFI coeff. mean in true model"
	putexcel B`row++' = "# projects er > 2 coeff. mean"
	putexcel B`row++' = "pc coeff. mean in true model"
	putexcel B`row++' = "DFI coeff. bias mean"
	putexcel B`row++' = "Cov(z,u) mean"
	putexcel B`row++' = "Cov(z,x) mean"
	putexcel B`row++' = "Var(z) mean"
	putexcel B`row++' = "DFI coeff. bias mean"
	putexcel B`row++' = "Corr(z,u) mean"
	putexcel B`row++' = "Corr(z,x) mean"
	putexcel B`row++' = "Sd(u) mean"
	putexcel B`row++' = "Sd(x) mean"
	putexcel B`row++' = "DFI coeff. bias median"
	putexcel B`row++' = "Cov(z,u) median"
	putexcel B`row++' = "Cov(z,x) median"
	putexcel B`row++' = "Var(z) median"
	putexcel B`row++' = "DFI coeff. bias median"
	putexcel B`row++' = "Corr(z,u) median"
	putexcel B`row++' = "Corr(z,x) median"
	putexcel B`row++' = "Sd(u) median"
	putexcel B`row++' = "Sd(x) median"
	//
	putexcel B`row++' = " "
	putexcel B`row++' = "Number of datasets where max db exceeds # proj. er > 2"
	putexcel B`row++' = "# successful replications"
	putexcel B`row++' = "Med. of med. DFI inv/private"
	//
	putexcel C1= "default, pc noise 0.5"
	putexcel D1= "fewertrans, pc noise 0.5"
	putexcel E1= "oneperiodchange, pc noise 0.5"
	putexcel F1= "fixedtypes, pc noise 0.5"
	putexcel G1= "oneperiodchange, pc noise 0.5, phi = 1"
	putexcel H1= "oneperiodchange, pc noise 0.5, phi = 2"
	putexcel I1= "oneperiodchange, pc noise 0.5, phi = 2, sigma = 0.05"
	putexcel J1= "oneperiodchange, pc noise 1, phi = 2, sigma = 0.05"
	putexcel K1= "default, pc noise 0.5, downward drift 0.1"
	putexcel L1= "fewertrans, pc noise 0.5, downward drift 0.1"
	putexcel M1= "fixedtypes, pc noise 0.5, downward drift 0.1"
	putexcel N1= "default, pc noise 0.5, upward drift 0.05"
	putexcel O1= "fewertrans, pc noise 0.5, upward drift 0.05"
	putexcel P1= "fixedtypes, pc noise 0.5, upward drift 0.05"
	
	
	/* Now generate tables to export to TeX, using texdoc. */
	texdoc init "`tablesexport'/IVexport_zeroadd_`option'.tex", replace force
	tex  								  & \mcolsfe{(1)} 				      & \mcolsfe{(2)} 				         & \mcolsfe{(3)} 				         & \mcolsfe{(4)} 					    & \mcolsfe{(5)} 				    & \mcolsfe{(6)} 				       & \mcolsfe{(7)} 						   \\
	tex $\Delta$ types                    & \mcolsfe{default}                 & \mcolsfe{fewer}                      & \mcolsfe{1period}                     & \mcolsfe{fixed}                      & \mcolsfe{1period}                 & \mcolsfe{1period}                    & \mcolsfe{1period}                     \\
	tex $\phi$                            & \mcc{0}                           & \mcc{0}                              & \mcc{0}                               & \mcc{0}                              & \mcc{1}                           & \mcc{2}                              & \mcc{2}                               \\
	tex $\mathit{pc}$                     & \mcolsfe{excl.}                   & \mcolsfe{excl.}                      & \mcolsfe{excl.}                       & \mcolsfe{excl.}                      & \mcolsfe{excl.}                   & \mcolsfe{excl.}                      & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}} \\
	tex $\sigma_{db}$                     & \mcc{0.15}                        & \mcc{0.15}                           & \mcc{0.15}                            & \mcc{0.15}                           & \mcc{0.15}                        & \mcc{0.15}                           & \mcc{0.05}                            \\
	tex \cmidrule{1-8}
	tex Med.\ $\widehat{\beta}_{IV}$      & `IVbetadfimedian1'                & `IVbetadfimedian2'                   & `IVbetadfimedian3'                    & `IVbetadfimedian4'                   & `IVbetadfimedian5'                & `IVbetadfimedian6'                   & `IVpcbetadfimedian7'                  \\
	tex Std.\ dev.\	                      & \mcc{`IVbetadfisd1'}              & \mcc{`IVbetadfisd2'}                 & \mcc{`IVbetadfisd3'}                  & \mcc{`IVbetadfisd4'}                 & \mcc{`IVbetadfisd5'}              & \mcc{`IVbetadfisd6'}                 & \mcc{`IVpcbetadfisd7'}                \\
	tex \% reject $\beta \leqslant 0$     & \mcc{`IVzeroaddpercreject1'}      & \mcc{`IVzeroaddpercreject2'}         & \mcc{`IVzeroaddpercreject3'}          & \mcc{`IVzeroaddpercreject4'}         & \mcc{`IVzeroaddpercreject5'}      & \mcc{`IVzeroaddpercreject6'}         & \mcc{`IVpczeroaddpercreject7'}        \\
	tex Med.\ F                           & \mcc{`IVmedFSF1'}                 & \mcc{`IVmedFSF2'}                    & \mcc{`IVmedFSF3'}                     & \mcc{`IVmedFSF4'}                    & \mcc{`IVmedFSF5'}                 & \mcc{`IVmedFSF6'}                    & \mcc{`IVpcmedFSF7'}                   \\
	tex \mbox{\% reject underid.}         & \mcc{`IVunderidpercreject1'}      & \mcc{`IVunderidpercreject2'}         & \mcc{`IVunderidpercreject3'}          & \mcc{`IVunderidpercreject4'}         & \mcc{`IVunderidpercreject5'}      & \mcc{`IVunderidpercreject6'}         & \mcc{`IVpcunderidpercreject7'}        \\
	tex \bottomrule
	texdoc close

	// same table but with leave-one-out version of instrument, for appendix
	texdoc init "`tablesexport'/IVexport_zeroaddapp_`option'.tex", replace force
	tex  								  & \mcolsfe{(1)} 				      & \mcolsfe{(2)} 				         & \mcolsfe{(3)} 				         & \mcolsfe{(4)} 					    & \mcolsfe{(5)} 				    & \mcolsfe{(6)} 				       & \mcolsfe{(7)} 						   & \mcolsfe{(8)} \\
	tex $\Delta$ types                    & \mcolsfe{default}                 & \mcolsfe{fewer}                      & \mcolsfe{1period}                     & \mcolsfe{fixed}                      & \mcolsfe{1period}                 & \mcolsfe{1period}                    & \mcolsfe{1period}                     & \mcolsfe{1period}  \\
	tex $\phi$                            & \mcc{0}                           & \mcc{0}                              & \mcc{0}                               & \mcc{0}                              & \mcc{1}                           & \mcc{2}                              & \mcc{2}                               & \mcc{1}                      \\
	tex $\mathit{pc}$                     & \mcolsfe{excl.}                   & \mcolsfe{excl.}                      & \mcolsfe{excl.}                       & \mcolsfe{excl.}                      & \mcolsfe{excl.}                   & \mcolsfe{excl.}                      & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}} & \mcolsfe{excl.} \\
	tex $\sigma_{db}$                     & \mcc{0.15}                        & \mcc{0.15}                           & \mcc{0.15}                            & \mcc{0.15}                           & \mcc{0.15}                        & \mcc{0.15}                           & \mcc{0.05}                            & \mcc{0.15}                   \\
	tex Instrument                     	  & \mcolsfe{standard}                & \mcolsfe{standard}                   & \mcolsfe{standard}                    & \mcolsfe{standard}                   & \mcolsfe{standard}                & \mcolsfe{standard}                   & \mcolsfe{standard}                    & \mcolsfe{leave1out}                   \\
	tex \cmidrule{1-9}
	tex Med.\ $\widehat{\beta}_{IV}$      & `IVbetadfimedian1'                & `IVbetadfimedian2'                   & `IVbetadfimedian3'                    & `IVbetadfimedian4'                   & `IVbetadfimedian5'                & `IVbetadfimedian6'                   & `IVpcbetadfimedian7'                  & `IVbetadfimedianl1out5'   \\
	tex Std.\ dev.\	                      & \mcc{`IVbetadfisd1'}              & \mcc{`IVbetadfisd2'}                 & \mcc{`IVbetadfisd3'}                  & \mcc{`IVbetadfisd4'}                 & \mcc{`IVbetadfisd5'}              & \mcc{`IVbetadfisd6'}                 & \mcc{`IVpcbetadfisd7'}                & \mcc{`IVbetadfil1outsd5'}   \\
	tex \% reject $\beta \leqslant 0$     & \mcc{`IVzeroaddpercreject1'}      & \mcc{`IVzeroaddpercreject2'}         & \mcc{`IVzeroaddpercreject3'}          & \mcc{`IVzeroaddpercreject4'}         & \mcc{`IVzeroaddpercreject5'}      & \mcc{`IVzeroaddpercreject6'}         & \mcc{`IVpczeroaddpercreject7'}        & \mcc{`IVzeroaddpercrejectl1out5'} \\
	tex Med.\ F                           & \mcc{`IVmedFSF1'}                 & \mcc{`IVmedFSF2'}                    & \mcc{`IVmedFSF3'}                     & \mcc{`IVmedFSF4'}                    & \mcc{`IVmedFSF5'}                 & \mcc{`IVmedFSF6'}                    & \mcc{`IVpcmedFSF7'}                   & \mcc{`IVmedFSFl1out5'} \\
	tex \mbox{\% reject underid.}         & \mcc{`IVunderidpercreject1'}      & \mcc{`IVunderidpercreject2'}         & \mcc{`IVunderidpercreject3'}          & \mcc{`IVunderidpercreject4'}         & \mcc{`IVunderidpercreject5'}      & \mcc{`IVunderidpercreject6'}         & \mcc{`IVpcunderidpercreject7'}        & \mcc{`IVunderidpercrejectl1out5'} \\
	tex \bottomrule
	texdoc close

	
	// second table, with downward trend
	texdoc init "`tablesexport'/IVtrendsdownexport_zeroadd_`option'.tex", replace force
	tex  								  & \mcolsfe{(1)} 				      & \mcolsfe{(2)} 				      & \mcolsfe{(3)} 				      & \mcolsfe{(4)} 				       & \mcolsfe{(5)} 					        \\
	tex $\mathit{drift}$                  & \mcc{-0.1}                        & \mcc{-0.1}                        & \mcc{-0.1}                        & \mcc{-0.1}                         & \mcc{-0.1}                             \\
	tex $\Delta$ types                    & \mcolsfe{default}                 & \mcolsfe{fewer}                   & \mcolsfe{fixed}                   & \mcolsfe{default}                  & \mcolsfe{default}                      \\
	tex i.trend                           & \mcolsfe{no}                      & \mcolsfe{no}                      & \mcolsfe{no}                      & \mcolsfe{yes}                      & \mcolsfe{no}                           \\
	tex $\mathit{pc}$                     & \mcolsfe{excl.}                   & \mcolsfe{excl.}                   & \mcolsfe{excl.}                   & \mcolsfe{excl.}                    & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}}  \\
	tex \cmidrule{1-6}                                                                                         
	tex Med.\ $\widehat{\beta}_{IV}$      & `IVbetadfimedian9'                & `IVbetadfimedian10'               & `IVbetadfimedian11'               & `IVbetadfictmedian9'               & `IVpcbetadfimedian9'                   \\
	tex Std.\ dev.\	                      & \mcc{`IVbetadfisd9'}              & \mcc{`IVbetadfisd10'}             & \mcc{`IVbetadfisd11'}             & \mcc{`IVbetadfictsd9'}             & \mcc{`IVpcbetadfisd9'}                 \\
	tex \% reject $\beta \leqslant 0$     & \mcc{`IVzeroaddpercreject9'}      & \mcc{`IVzeroaddpercreject10'}     & \mcc{`IVzeroaddpercreject11'}     & \mcc{`IVzeroaddpercrejectct9'}     & \mcc{`IVpczeroaddpercreject9'}         \\
	tex Med.\ F                           & \mcc{`IVmedFSF9'}                 & \mcc{`IVmedFSF10'}                & \mcc{`IVmedFSF11'}                & \mcc{`IVmedFSFct9'}                & \mcc{`IVpcmedFSF9'}                    \\
	tex \mbox{\% reject underid.}         & \mcc{`IVunderidpercreject9'}      & \mcc{`IVunderidpercreject10'}     & \mcc{`IVunderidpercreject11'}     & \mcc{`IVunderidpercrejectct9'}     & \mcc{`IVpcunderidpercreject9'}         \\
	tex Med.\ FS    					  & `IVbetaFSmedian9'                 & `IVbetaFSmedian10'                & `IVbetaFSmedian11'                & `IVbetactFSmedian9'                & `IVpcbetaFSmedian9'                    \\
	tex Med.\ RF    					  & `IVbetaRFmedian9'                 & `IVbetaRFmedian10'                & `IVbetaRFmedian11'                & `IVbetactRFmedian9'                & `IVpcbetaRFmedian9'                    \\
	tex \bottomrule
	texdoc close

	// Upward trend
	texdoc init "`tablesexport'/IVtrendsupexport_zeroadd_`option'.tex", replace force
	tex  								  & \mcolsfe{(1)} 				      & \mcolsfe{(2)} 				    & \mcolsfe{(3)} 				  & \mcolsfe{(4)} 					  & \mcolsfe{(5)} \\
	tex $\mathit{drift}$                  & \mcc{0.05}                        & \mcc{0.05}                      & \mcc{0.05}                      & \mcc{0.05}                        & \mcc{0.05} \\
	tex $\Delta$ types                    & \mcolsfe{default}                 & \mcolsfe{fewer}                 & \mcolsfe{fixed}                 & \mcolsfe{default}                 & \mcolsfe{default}  \\
	tex i.trend                           & \mcolsfe{no}                      & \mcolsfe{no}                    & \mcolsfe{no}                    & \mcolsfe{yes}                     & \mcolsfe{no}  \\
	tex $\mathit{pc}$                     & \mcolsfe{excl.}                   & \mcolsfe{excl.}                 & \mcolsfe{excl.}                 & \mcolsfe{excl.}                   & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}} \\
	tex \cmidrule{1-6}                                                                                          
	tex Med.\ $\widehat{\beta}_{IV}$      & `IVbetadfimedian12'               & `IVbetadfimedian13'             & `IVbetadfimedian14'             & `IVbetadfictmedian12'             & `IVpcbetadfimedian12'   \\
	tex Std.\ dev.\	                      & \mcc{`IVbetadfisd12'}             & \mcc{`IVbetadfisd13'}           & \mcc{`IVbetadfisd14'}           & \mcc{`IVbetadfictsd12'}           & \mcc{`IVpcbetadfisd12'}   \\
	tex \% reject $\beta \leqslant 0$     & \mcc{`IVzeroaddpercreject12'}     & \mcc{`IVzeroaddpercreject13'}   & \mcc{`IVzeroaddpercreject14'}   & \mcc{`IVzeroaddpercrejectct12'}   & \mcc{`IVpczeroaddpercreject12'} \\
	tex Med.\ F                           & \mcc{`IVmedFSF12'}                & \mcc{`IVmedFSF13'}              & \mcc{`IVmedFSF14'}              & \mcc{`IVmedFSFct12'}              & \mcc{`IVpcmedFSF12'} \\
	tex \mbox{\% reject underid.}         & \mcc{`IVunderidpercreject12'}     & \mcc{`IVunderidpercreject13'}   & \mcc{`IVunderidpercreject14'}   & \mcc{`IVunderidpercrejectct12'}   & \mcc{`IVpcunderidpercreject12'} \\
	tex Med.\ FS    					  & `IVbetaFSmedian12'                & `IVbetaFSmedian13'              & `IVbetaFSmedian14'              & `IVbetactFSmedian12'              & `IVpcbetaFSmedian12'   \\
	tex Med.\ RF    					  & `IVbetaRFmedian12'                & `IVbetaRFmedian13'              & `IVbetaRFmedian14'              & `IVbetactRFmedian12'              & `IVpcbetaRFmedian12'   \\
	tex \bottomrule
	texdoc close
} // end loop over exclhighdb or not


*************************************************************************
* SUPPLY-PUSH IV WITH FULL ADDITIONALITY
*************************************************************************
foreach num of numlist 1/14 {
	clear
	capture log close
	log using "./Generated data/IVfulladd`num'", replace text
	use "./Generated data/IVfulladd`num'.dta"


	/* First check if all replications have been successful. */
	egen nummissing = rowmiss(ivbetadfi-type3dfiinvIVy20)
	tab nummissing, missing
	count if nummissing == 0
	scalar successfulreps = r(N)
	foreach var of varlist * { 
		replace `var' = . if nummissing != 0
	}

		
	/* Now pick up selected IV statistics to export to Excel later: */
	su ivbetadfi, detail
	scalar IVbetadfimean=r(mean)
	scalar IVbetadfimedian=r(p50)
	local IVbetadfimedian`num': di %4.2f IVbetadfimedian				
	scalar IVbetadfisd=r(sd)
	local IVbetadfisd`num': di %4.2f IVbetadfisd							
	su febetadfi, detail
	scalar FEbetadfimean=r(mean)
	scalar FEbetadfimedian=r(p50)
	su ivbetadfil1out, detail
	scalar IVbetadfil1outmedian=r(p50)
	local IVbetadfimedianl1out`num': di %4.2f IVbetadfil1outmedian				
	scalar IVbetadfil1outsd=r(sd)
	local IVbetadfil1outsd`num': di %4.2f IVbetadfil1outsd							
	su ivbetadfict, detail
	scalar IVbetadfictmedian=r(p50)
	local IVbetadfictmedian`num': di %4.2f IVbetadfictmedian				
	scalar IVbetadfictsd=r(sd)
	local IVbetadfictsd`num': di %4.2f IVbetadfictsd							
	//
	su ivpcbetadfi, detail
	scalar IVpcbetadfimean=r(mean)
	scalar IVpcbetadfimedian=r(p50)
	local IVpcbetadfimedian`num': di %4.2f IVpcbetadfimedian				
	scalar IVpcbetadfisd=r(sd)
	local IVpcbetadfisd`num': di %4.2f IVpcbetadfisd						
	su fepcbetadfi, detail
	scalar FEpcbetadfimean=r(mean)
	scalar FEpcbetadfimedian=r(p50)
	su ivpcbetadfil1out, detail
	scalar IVpcbetadfil1outmedian=r(p50)
	//		
	count if ivpfulladd < 0.05
	scalar IVfulladdpercreject=(r(N)/successfulreps)*100
	local IVfulladdpercreject`num': di %5.0g IVfulladdpercreject
	count if ivpfulladdl1out < 0.05
	scalar IVfulladdpercrejectl1out=(r(N)/successfulreps)*100
	local IVfulladdpercrejectl1out`num': di %5.0g IVfulladdpercrejectl1out
	count if ivpfulladdct < 0.05
	scalar IVfulladdpercrejectct=(r(N)/successfulreps)*100
	local IVfulladdpercrejectct`num': di %5.0g IVfulladdpercrejectct
	//
	count if ivpcpfulladd < 0.05
	scalar IVpcfulladdpercreject=(r(N)/successfulreps)*100
	local IVpcfulladdpercreject`num': di %5.0g IVpcfulladdpercreject
	count if ivpcpfulladdl1out < 0.05
	scalar IVpcfulladdpercrejectl1out=(r(N)/successfulreps)*100
	//
	su weakid, detail
	scalar IVmedFSF=r(p50)
	local IVmedFSF`num': di %5.0g IVmedFSF
	scalar IVminFSF=r(min)
	count if weakid > 10 & weakid != .
	scalar IVFSFpercover10=(r(N)/successfulreps)*100
	su weakidl1out, detail
	scalar IVmedFSFl1out=r(p50)
	local IVmedFSFl1out`num': di %5.0g IVmedFSFl1out
	su weakidct, detail
	scalar IVmedFSFct=r(p50)
	local IVmedFSFct`num': di %5.0g IVmedFSFct
	su underid, detail
	scalar IVmedFSLM=r(p50)
	scalar IVminFSLM=r(min)
	count if underid > 10 & underid != .
	scalar IVFSLMpercover10=(r(N)/successfulreps)*100
	su underidl1out, detail
	scalar IVmedFSLMl1out=r(p50)
	su underidct, detail
	scalar IVmedFSLMct=r(p50)
	count if underidp < 0.05
	scalar IVunderidpercreject=(r(N)/successfulreps)*100
	local IVunderidpercreject`num': di %5.0g IVunderidpercreject
	count if underidpl1out < 0.05
	scalar IVunderidpercrejectl1out=(r(N)/successfulreps)*100	
	local IVunderidpercrejectl1out`num': di %5.0g IVunderidpercrejectl1out
	count if underidpct < 0.05
	scalar IVunderidpercrejectct=(r(N)/successfulreps)*100	
	local IVunderidpercrejectct`num': di %5.0g IVunderidpercrejectct
	//
	su weakidpc, detail
	scalar IVpcmedFSF=r(p50)
	local IVpcmedFSF`num': di %5.0g IVpcmedFSF
	scalar IVpcminFSF=r(min)
	count if weakidpc > 10 & weakidpc != .
	scalar IVpcFSFpercover10=(r(N)/successfulreps)*100
	su weakidpcl1out, detail
	scalar IVpcmedFSFl1out=r(p50)
	su underidpc, detail
	scalar IVpcmedFSLM=r(p50)
	scalar IVpcminFSLM=r(min)
	count if underidpc > 10 & underidpc != .
	scalar IVpcFSLMpercover10=(r(N)/successfulreps)*100
	su underidpcl1out, detail
	scalar IVpcmedFSLMl1out=r(p50)
	count if underidppc < 0.05
	scalar IVpcunderidpercreject=(r(N)/successfulreps)*100
	local IVpcunderidpercreject`num': di %5.0g IVpcunderidpercreject
	count if underidppcl1out < 0.05
	scalar IVpcunderidpercrejectl1out=(r(N)/successfulreps)*100	
	//
	su ivFSbeta, detail
	scalar IVbetaFSmean=r(mean)
	scalar IVbetaFSmedian=r(p50)
	scalar IVbetaFSsd=r(sd)
	local IVbetaFSmedian`num': di %4.2f IVbetaFSmedian				
	su ivRFbeta, detail
	scalar IVbetaRFmean=r(mean)
	scalar IVbetaRFmedian=r(p50)
	scalar IVbetaRFsd=r(sd)
	local IVbetaRFmedian`num': di %4.2f IVbetaRFmedian				
	su ivFSbetact, detail
	scalar IVbetactFSmean=r(mean)
	scalar IVbetactFSmedian=r(p50)
	scalar IVbetactFSsd=r(sd)
	local IVbetactFSmedian`num': di %4.2f IVbetactFSmedian				
	su ivRFbetact, detail
	scalar IVbetactRFmean=r(mean)
	scalar IVbetactRFmedian=r(p50)
	scalar IVbetactRFsd=r(sd)
	local IVbetactRFmedian`num': di %4.2f IVbetactRFmedian				
	//
	su ivpcFSbeta, detail
	scalar IVpcbetaFSmean=r(mean)
	scalar IVpcbetaFSmedian=r(p50)
	scalar IVpcbetaFSsd=r(sd)
	local IVpcbetaFSmedian`num': di %4.2f IVpcbetaFSmedian				
	su ivpcRFbeta, detail
	scalar IVpcbetaRFmean=r(mean)
	scalar IVpcbetaRFmedian=r(p50)
	scalar IVpcbetaRFsd=r(sd)
	local IVpcbetaRFmedian`num': di %4.2f IVpcbetaRFmedian				

	
	/* Bias in IV */
	su ivbetadfitrue, detail
	scalar IVbetadfitruemean = r(mean)
	su ivbetanumprojerover2, detail
	scalar IVbetanumprojerover2mean = r(mean)
	// with pc
	su ivpcbetadfitrue, detail
	scalar IVpcbetadfitruemean = r(mean)
	su ivpcbetanumprojerover2, detail
	scalar IVpcbetanumprojerover2mean = r(mean)
	su ivpcbetapctrue, detail
	scalar IVpcbetapctruemean = r(mean)
	//
	gen double bias = covzu/covzx
	su bias, detail
	scalar IVbiasdfimean = r(mean)
	scalar IVbiasdfimedian = r(p50)
	gen double bias2 = (corrzu/corrzx)*(sdu/sdx)
	su bias2, detail 
	scalar IVbias2dfimean = r(mean)
	scalar IVbias2dfimedian = r(p50)
	su covzu, detail
	scalar IVcovzumean = r(mean)
	scalar IVcovzumedian = r(p50)
	su covzx, detail
	scalar IVcovzxmean = r(mean)
	scalar IVcovzxmedian = r(p50)
	su varz, detail
	scalar IVvarzmean = r(mean)
	scalar IVvarzmedian = r(p50)
	su corrzu, detail
	scalar IVcorrzumean = r(mean)
	scalar IVcorrzumedian = r(p50)
	su corrzx, detail
	scalar IVcorrzxmean = r(mean)
	scalar IVcorrzxmedian = r(p50)
	su sdu, detail
	scalar IVsdumean = r(mean)
	scalar IVsdumedian = r(p50)
	su sdx, detail
	scalar IVsdxmean = r(mean)
	scalar IVsdxmedian = r(p50)
	//
	gen double pcbias = pccovzu/pccovzx
	su pcbias, detail
	scalar IVpcbiasdfimean = r(mean)
	scalar IVpcbiasdfimedian = r(p50)
	gen double pcbias2 = (pccorrzu/pccorrzx)*(pcsdu/pcsdx)
	su pcbias2, detail
	scalar IVpcbias2dfimean = r(mean)
	scalar IVpcbias2dfimedian = r(p50)
	su pccovzu, detail
	scalar IVpccovzumean = r(mean)
	scalar IVpccovzumedian = r(p50)
	su pccovzx, detail
	scalar IVpccovzxmean = r(mean)
	scalar IVpccovzxmedian = r(p50)
	su pcvarz, detail
	scalar IVpcvarzmean = r(mean)
	scalar IVpcvarzmedian = r(p50)
	su pccorrzu, detail
	scalar IVpccorrzumean = r(mean)
	scalar IVpccorrzumedian = r(p50)
	su pccorrzx, detail
	scalar IVpccorrzxmean = r(mean)
	scalar IVpccorrzxmedian = r(p50)
	su pcsdu, detail
	scalar IVpcsdumean = r(mean)
	scalar IVpcsdumedian = r(p50)
	su pcsdx, detail
	scalar IVpcsdxmean = r(mean)
	scalar IVpcsdxmedian = r(p50)
	
	
	/* Evolution of variables by type */
	foreach var of varlist type1invy1-type3dfiinvIVy20 {
		su `var', detail
		scalar `var'med = r(p50)
	}

	
	count if maxdbpercnumprojerover2 >= 1 & maxdbpercnumprojerover2 != .
	scalar countmaxdbpercnumprojerover2exc1 = r(N)

	su medinvDFIvsprivate, detail
	scalar medmedinvDFIvsprivate = r(p50)
	
	scalar empty = .
	scalar number = `num'

	
	// Put statistics in matrix:
	matrix IVfulladd_`num' = (number \ IVbetadfimean \ IVbetadfimedian \ IVbetadfisd \ IVfulladdpercreject /// 
	\ IVmedFSF \ IVminFSF \ IVFSFpercover10 \ IVmedFSLM \ IVminFSLM \ IVFSLMpercover10 \ IVunderidpercreject ///
	\ IVbetaFSmean \ IVbetaFSmedian \ IVbetaFSsd \ IVbetaRFmean \ IVbetaRFmedian \ IVbetaRFsd \ FEbetadfimean \ FEbetadfimedian ///
	\ IVbetadfil1outmedian \ IVfulladdpercrejectl1out /// 
	\ IVmedFSFl1out \ IVmedFSLMl1out \ IVunderidpercrejectl1out ///
	\ IVbetadfictmedian \ IVfulladdpercrejectct /// 
	\ IVmedFSFct \ IVmedFSLMct \ IVunderidpercrejectct ///
	\ IVbetactFSmean \ IVbetactFSmedian \ IVbetactFSsd \ IVbetactRFmean \ IVbetactRFmedian \ IVbetactRFsd ///
	\ IVbetadfitruemean \ IVbetanumprojerover2mean \ IVbiasdfimean \ IVcovzumean \ IVcovzxmean \ IVvarzmean \ IVbias2dfimean \ IVcorrzumean \ IVcorrzxmean \ IVsdumean \ IVsdxmean ///
	\ IVbiasdfimedian \ IVcovzumedian \ IVcovzxmedian \ IVvarzmedian \ IVbias2dfimedian \ IVcorrzumedian \ IVcorrzxmedian \ IVsdumedian \ IVsdxmedian \ empty ///
	\ type1invy1med \ type1invy20med \ type2invy1med \ type2invy20med \ type3invy1med \ type3invy20med ///
	\ type1dfiinvy1med \ type1dfiinvy20med \ type2dfiinvy1med \ type2dfiinvy20med \ type3dfiinvy1med \ type3dfiinvy20med ///
	\ type1dfiinvIVy1med \ type1dfiinvIVy20med \ type2dfiinvIVy1med \ type2dfiinvIVy20med \ type3dfiinvIVy1med \ type3dfiinvIVy20med \ empty /// 
	\ IVpcbetadfimean \ IVpcbetadfimedian \ IVpcbetadfisd \ IVpcfulladdpercreject ///
	\ IVpcmedFSF \ IVpcminFSF \ IVpcFSFpercover10 \ IVpcmedFSLM \ IVpcminFSLM \ IVpcFSLMpercover10 \ IVpcunderidpercreject /// 
	\ IVpcbetaFSmean \ IVpcbetaFSmedian \ IVpcbetaFSsd \ IVpcbetaRFmean \ IVpcbetaRFmedian \ IVpcbetaRFsd \ FEpcbetadfimean \ FEpcbetadfimedian ///
	\ IVpcbetadfil1outmedian \ IVpcfulladdpercrejectl1out ///
	\ IVpcmedFSFl1out \ IVpcmedFSLMl1out \ IVpcunderidpercrejectl1out ///
	\ IVpcbetadfitruemean \ IVpcbetanumprojerover2mean \ IVpcbetapctruemean \ IVpcbiasdfimean \ IVpccovzumean \ IVpccovzxmean \ IVpcvarzmean /// 
	\ IVpcbias2dfimean \ IVpccorrzumean \ IVpccorrzxmean \ IVpcsdumean \ IVpcsdxmean /// 
	\ IVpcbiasdfimedian \ IVpccovzumedian \ IVpccovzxmedian \ IVpcvarzmedian \ IVpcbias2dfimedian /// 
	\ IVpccorrzumedian \ IVpccorrzxmedian \ IVpcsdumedian \ IVpcsdxmedian /// 
	\ empty \ countmaxdbpercnumprojerover2exc1 \ successfulreps \ medmedinvDFIvsprivate)
	matrix list IVfulladd_`num'
	
	log close
}


/* Construct matrices that combine results. */
foreach num of numlist 1/14 {
	if `num'==1 { 
		matrix tableIVfulladd = IVfulladd_`num'
	}
	else { 
		matrix tableIVfulladd=(tableIVfulladd, IVfulladd_`num')
	}        
}

 
/* Export to Excel and clean up tables. */
putexcel set "./Tables/IVfulladdtable_", replace
putexcel C2 = matrix(tableIVfulladd) // starting point of table
//
putexcel A3 = "Without pc"
putexcel A20 = "FE (no IV)"
putexcel A22 = "Leave 1 out"
putexcel A27 = "Country trend"
putexcel A38 = "Analyse bias"
putexcel A59 = "Evolution of types"
putexcel A78 = "With pc"
putexcel A95 = "FE (no IV)"
putexcel A97 = "Leave 1 out"
putexcel A103 = "Analyse bias"
//
local row 3
putexcel B`row++' = "DFI coeff. mean"
putexcel B`row++' = "DFI coeff. median"
putexcel B`row++' = "DFI coeff. st. dev."
putexcel B`row++' = "% reject full additionality"
putexcel B`row++' = "Median FS F"
putexcel B`row++' = "Min. FS F"
putexcel B`row++' = "% FS F > 10"
putexcel B`row++' = "Median FS LM"
putexcel B`row++' = "Min. FS LM"
putexcel B`row++' = "% FS LM > 10"
putexcel B`row++' = "% reject underidentification"
putexcel B`row++' = "FS instr. coeff. mean"
putexcel B`row++' = "FS instr. coeff. median"
putexcel B`row++' = "FS instr. coeff. st. dev."
putexcel B`row++' = "RF instr. coeff. mean"
putexcel B`row++' = "RF instr. coeff. median"
putexcel B`row++' = "RF instr. coeff. st. dev."
putexcel B`row++' = "FE DFI coeff. mean"
putexcel B`row++' = "FE DFI coeff. median"
putexcel B`row++' = "DFI coeff. median leave 1 out"
putexcel B`row++' = "% reject full add. leave 1 out"
putexcel B`row++' = "Median FS F leave 1 out"
putexcel B`row++' = "Median FS LM leave 1 out"
putexcel B`row++' = "% reject underid. leave 1 out"
putexcel B`row++' = "DFI coeff. median country trend"
putexcel B`row++' = "% reject full add. country trend"
putexcel B`row++' = "Median FS F country trend"
putexcel B`row++' = "Median FS LM country trend"
putexcel B`row++' = "% reject underid. country trend"
putexcel B`row++' = "FS instr. coeff. mean"
putexcel B`row++' = "FS instr. coeff. median"
putexcel B`row++' = "FS instr. coeff. st. dev."
putexcel B`row++' = "RF instr. coeff. mean"
putexcel B`row++' = "RF instr. coeff. median"
putexcel B`row++' = "RF instr. coeff. st. dev."
putexcel B`row++' = "DFI coeff. mean in true model"
putexcel B`row++' = "# projects er > 2 coeff. mean"
putexcel B`row++' = "DFI coeff. bias mean"
putexcel B`row++' = "Cov(z,u) mean"
putexcel B`row++' = "Cov(z,x) mean"
putexcel B`row++' = "Var(z) mean"
putexcel B`row++' = "DFI coeff. bias mean"
putexcel B`row++' = "Corr(z,u) mean"
putexcel B`row++' = "Corr(z,x) mean"
putexcel B`row++' = "Sd(u) mean"
putexcel B`row++' = "Sd(x) mean"
putexcel B`row++' = "DFI coeff. bias median"
putexcel B`row++' = "Cov(z,u) median"
putexcel B`row++' = "Cov(z,x) median"
putexcel B`row++' = "Var(z) median"
putexcel B`row++' = "DFI coeff. bias median"
putexcel B`row++' = "Corr(z,u) median"
putexcel B`row++' = "Corr(z,x) median"
putexcel B`row++' = "Sd(u) median"
putexcel B`row++' = "Sd(x) median"
putexcel B`row++' = " "
putexcel B`row++' = "Type 1 median inv Y1"
putexcel B`row++' = "Type 1 median inv Y20"
putexcel B`row++' = "Type 2 median inv Y1"
putexcel B`row++' = "Type 2 median inv Y20"
putexcel B`row++' = "Type 3 median inv Y1"
putexcel B`row++' = "Type 3 median inv Y20"
putexcel B`row++' = "Type 1 median DFI inv Y1"
putexcel B`row++' = "Type 1 median DFI inv Y20"
putexcel B`row++' = "Type 2 median DFI inv Y1"
putexcel B`row++' = "Type 2 median DFI inv Y20"
putexcel B`row++' = "Type 3 median DFI inv Y1"
putexcel B`row++' = "Type 3 median DFI inv Y20"
putexcel B`row++' = "Type 1 median DFI inv IV Y1"
putexcel B`row++' = "Type 1 median DFI inv IV Y20"
putexcel B`row++' = "Type 2 median DFI inv IV Y1"
putexcel B`row++' = "Type 2 median DFI inv IV Y20"
putexcel B`row++' = "Type 3 median DFI inv IV Y1"
putexcel B`row++' = "Type 3 median DFI inv IV Y20"
//
putexcel B`row++' = " "
putexcel B`row++' = "DFI coeff. mean"
putexcel B`row++' = "DFI coeff. median"
putexcel B`row++' = "DFI coeff. st. dev."
putexcel B`row++' = "% reject full additionality"
putexcel B`row++' = "Median FS F"
putexcel B`row++' = "Min. FS F"
putexcel B`row++' = "% FS F > 10"
putexcel B`row++' = "Median FS LM"
putexcel B`row++' = "Min. FS LM"
putexcel B`row++' = "% FS LM > 10"
putexcel B`row++' = "% reject underidentification"
putexcel B`row++' = "FS instr. coeff. mean"
putexcel B`row++' = "FS instr. coeff. median"
putexcel B`row++' = "FS instr. coeff. st. dev."
putexcel B`row++' = "RF instr. coeff. mean"
putexcel B`row++' = "RF instr. coeff. median"
putexcel B`row++' = "RF instr. coeff. st. dev."
putexcel B`row++' = "FE DFI coeff. mean"
putexcel B`row++' = "FE DFI coeff. median"
putexcel B`row++' = "DFI coeff. median leave 1 out"
putexcel B`row++' = "% reject full add. leave 1 out"
putexcel B`row++' = "Median FS F leave 1 out"
putexcel B`row++' = "Median FS LM leave 1 out"
putexcel B`row++' = "% reject underid. leave 1 out"
putexcel B`row++' = "DFI coeff. mean in true model"
putexcel B`row++' = "# projects er > 2 coeff. mean"
putexcel B`row++' = "pc coeff. mean in true model"
putexcel B`row++' = "DFI coeff. bias mean"
putexcel B`row++' = "Cov(z,u) mean"
putexcel B`row++' = "Cov(z,x) mean"
putexcel B`row++' = "Var(z) mean"
putexcel B`row++' = "DFI coeff. bias mean"
putexcel B`row++' = "Corr(z,u) mean"
putexcel B`row++' = "Corr(z,x) mean"
putexcel B`row++' = "Sd(u) mean"
putexcel B`row++' = "Sd(x) mean"
putexcel B`row++' = "DFI coeff. bias median"
putexcel B`row++' = "Cov(z,u) median"
putexcel B`row++' = "Cov(z,x) median"
putexcel B`row++' = "Var(z) median"
putexcel B`row++' = "DFI coeff. bias median"
putexcel B`row++' = "Corr(z,u) median"
putexcel B`row++' = "Corr(z,x) median"
putexcel B`row++' = "Sd(u) median"
putexcel B`row++' = "Sd(x) median"
//
putexcel B`row++' = " "
putexcel B`row++' = "Number of datasets where max db exceeds # proj. er > 2"
putexcel B`row++' = "# successful replications"
putexcel B`row++' = "Med. of med. DFI inv/private"
//
putexcel C1= "default, pc noise 0.5"
putexcel D1= "fewertrans, pc noise 0.5"
putexcel E1= "oneperiodchange, pc noise 0.5"
putexcel F1= "fixedtypes, pc noise 0.5"
putexcel G1= "oneperiodchange, pc noise 0.5, phi = 1"
putexcel H1= "oneperiodchange, pc noise 0.5, phi = 2"
putexcel I1= "oneperiodchange, pc noise 0.5, phi = 2, sigma = 0.05"
putexcel J1= "oneperiodchange, pc noise 1, phi = 2, sigma = 0.05"
putexcel K1= "default, pc noise 0.5, downward drift 0.1"
putexcel L1= "fewertrans, pc noise 0.5, downward drift 0.1"
putexcel M1= "fixedtypes, pc noise 0.5, downward drift 0.1"
putexcel N1= "default, pc noise 0.5, upward drift 0.05"
putexcel O1= "fewertrans, pc noise 0.5, upward drift 0.05"
putexcel P1= "fixedtypes, pc noise 0.5, upward drift 0.05"


/* Now generate tables to export to TeX, using texdoc. */
texdoc init "`tablesexport'/IVexport_fulladd_.tex", replace force
tex  								  & \mcolsfe{(1)} 				      & \mcolsfe{(2)} 				         & \mcolsfe{(3)} 				         & \mcolsfe{(4)} 					    & \mcolsfe{(5)} 				    & \mcolsfe{(6)} 				       & \mcolsfe{(7)} 						   & \mcolsfe{(8)} \\
tex $\Delta$ types                    & \mcolsfe{default}                 & \mcolsfe{fewer}                      & \mcolsfe{1period}                     & \mcolsfe{fixed}                      & \mcolsfe{1period}                 & \mcolsfe{1period}                    & \mcolsfe{1period}                     & \mcolsfe{1period}  \\
tex $\phi$                            & \mcc{0}                           & \mcc{0}                              & \mcc{0}                               & \mcc{0}                              & \mcc{1}                           & \mcc{2}                              & \mcc{2}                               & \mcc{1}                      \\
tex $\mathit{pc}$                     & \mcolsfe{excl.}                   & \mcolsfe{excl.}                      & \mcolsfe{excl.}                       & \mcolsfe{excl.}                      & \mcolsfe{excl.}                   & \mcolsfe{excl.}                      & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}} & \mcolsfe{excl.} \\
tex $\sigma_{db}$                     & \mcc{0.15}                        & \mcc{0.15}                           & \mcc{0.15}                            & \mcc{0.15}                           & \mcc{0.15}                        & \mcc{0.15}                           & \mcc{0.05}                            & \mcc{0.15}                   \\
tex Instrument                     	  & \mcolsfe{standard}                & \mcolsfe{standard}                   & \mcolsfe{standard}                    & \mcolsfe{standard}                   & \mcolsfe{standard}                & \mcolsfe{standard}                   & \mcolsfe{standard}                    & \mcolsfe{leave1out}                   \\
tex \cmidrule{1-9}
tex Med.\ $\widehat{\beta}_{IV}$      & `IVbetadfimedian1'                & `IVbetadfimedian2'                   & `IVbetadfimedian3'                    & `IVbetadfimedian4'                   & `IVbetadfimedian5'                & `IVbetadfimedian6'                   & `IVpcbetadfimedian7'                  & `IVbetadfimedianl1out5'   \\
tex Std.\ dev.\	                      & \mcc{`IVbetadfisd1'}              & \mcc{`IVbetadfisd2'}                 & \mcc{`IVbetadfisd3'}                  & \mcc{`IVbetadfisd4'}                 & \mcc{`IVbetadfisd5'}              & \mcc{`IVbetadfisd6'}                 & \mcc{`IVpcbetadfisd7'}                & \mcc{`IVbetadfil1outsd5'}   \\
tex \% reject $\beta \geqslant 1$     & \mcc{`IVfulladdpercreject1'}      & \mcc{`IVfulladdpercreject2'}         & \mcc{`IVfulladdpercreject3'}          & \mcc{`IVfulladdpercreject4'}         & \mcc{`IVfulladdpercreject5'}      & \mcc{`IVfulladdpercreject6'}         & \mcc{`IVpcfulladdpercreject7'}        & \mcc{`IVfulladdpercrejectl1out5'} \\
tex Med.\ F                           & \mcc{`IVmedFSF1'}                 & \mcc{`IVmedFSF2'}                    & \mcc{`IVmedFSF3'}                     & \mcc{`IVmedFSF4'}                    & \mcc{`IVmedFSF5'}                 & \mcc{`IVmedFSF6'}                    & \mcc{`IVpcmedFSF7'}                   & \mcc{`IVmedFSFl1out5'} \\
tex \mbox{\% reject underid.}         & \mcc{`IVunderidpercreject1'}      & \mcc{`IVunderidpercreject2'}         & \mcc{`IVunderidpercreject3'}          & \mcc{`IVunderidpercreject4'}         & \mcc{`IVunderidpercreject5'}      & \mcc{`IVunderidpercreject6'}         & \mcc{`IVpcunderidpercreject7'}        & \mcc{`IVunderidpercrejectl1out5'} \\
tex \bottomrule
texdoc close

// second table, with downward trend
texdoc init "`tablesexport'/IVtrendsdownexport_fulladd_.tex", replace force
tex  								  & \mcolsfe{(1)} 				      & \mcolsfe{(2)} 				      & \mcolsfe{(3)} 				      & \mcolsfe{(4)} 				       & \mcolsfe{(5)} 					        \\
tex $\mathit{drift}$                  & \mcc{-0.1}                        & \mcc{-0.1}                        & \mcc{-0.1}                        & \mcc{-0.1}                         & \mcc{-0.1}                             \\
tex $\Delta$ types                    & \mcolsfe{default}                 & \mcolsfe{fewer}                   & \mcolsfe{fixed}                   & \mcolsfe{default}                  & \mcolsfe{default}                      \\
tex i.trend                           & \mcolsfe{no}                      & \mcolsfe{no}                      & \mcolsfe{no}                      & \mcolsfe{yes}                      & \mcolsfe{no}                           \\
tex $\mathit{pc}$                     & \mcolsfe{excl.}                   & \mcolsfe{excl.}                   & \mcolsfe{excl.}                   & \mcolsfe{excl.}                    & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}}  \\
tex \cmidrule{1-6}                                                                                            
tex Med.\ $\widehat{\beta}_{IV}$      & `IVbetadfimedian9'                & `IVbetadfimedian10'               & `IVbetadfimedian11'               & `IVbetadfictmedian9'               & `IVpcbetadfimedian9'                   \\
tex Std.\ dev.\	                      & \mcc{`IVbetadfisd9'}              & \mcc{`IVbetadfisd10'}             & \mcc{`IVbetadfisd11'}             & \mcc{`IVbetadfictsd9'}             & \mcc{`IVpcbetadfisd9'}                 \\
tex \% reject $\beta \geqslant 1$     & \mcc{`IVfulladdpercreject9'}      & \mcc{`IVfulladdpercreject10'}     & \mcc{`IVfulladdpercreject11'}     & \mcc{`IVfulladdpercrejectct9'}     & \mcc{`IVpcfulladdpercreject9'}         \\
tex Med.\ F                           & \mcc{`IVmedFSF9'}                 & \mcc{`IVmedFSF10'}                & \mcc{`IVmedFSF11'}                & \mcc{`IVmedFSFct9'}                & \mcc{`IVpcmedFSF9'}                    \\
tex \mbox{\% reject underid.}         & \mcc{`IVunderidpercreject9'}      & \mcc{`IVunderidpercreject10'}     & \mcc{`IVunderidpercreject11'}     & \mcc{`IVunderidpercrejectct9'}     & \mcc{`IVpcunderidpercreject9'}         \\
tex Med.\ FS    					  & `IVbetaFSmedian9'                 & `IVbetaFSmedian10'                & `IVbetaFSmedian11'                & `IVbetactFSmedian9'                & `IVpcbetaFSmedian9'                    \\
tex Med.\ RF    					  & `IVbetaRFmedian9'                 & `IVbetaRFmedian10'                & `IVbetaRFmedian11'                & `IVbetactRFmedian9'                & `IVpcbetaRFmedian9'                    \\
tex \bottomrule
texdoc close

// Upward trend
texdoc init "`tablesexport'/IVtrendsupexport_fulladd_.tex", replace force
tex  								  & \mcolsfe{(1)} 				      & \mcolsfe{(2)} 				  & \mcolsfe{(3)} 				      & \mcolsfe{(4)} 					  & \mcolsfe{(5)} \\
tex $\mathit{drift}$                  & \mcc{0.05}                        & \mcc{0.05}                    & \mcc{0.05}                        & \mcc{0.05}                        & \mcc{0.05} \\
tex $\Delta$ types                    & \mcolsfe{default}                 & \mcolsfe{fewer}               & \mcolsfe{fixed}                   & \mcolsfe{default}                 & \mcolsfe{default}  \\
tex i.trend                           & \mcolsfe{no}                      & \mcolsfe{no}                  & \mcolsfe{no}                      & \mcolsfe{yes}                     & \mcolsfe{no}  \\
tex $\mathit{pc}$                     & \mcolsfe{excl.}                   & \mcolsfe{excl.}               & \mcolsfe{excl.}                   & \mcolsfe{excl.}                   & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}} \\
tex \cmidrule{1-6}                                                                                        
tex Med.\ $\widehat{\beta}_{IV}$      & `IVbetadfimedian12'               & `IVbetadfimedian13'           & `IVbetadfimedian14'               & `IVbetadfictmedian12'             & `IVpcbetadfimedian12'   \\
tex Std.\ dev.\	                      & \mcc{`IVbetadfisd12'}             & \mcc{`IVbetadfisd13'}         & \mcc{`IVbetadfisd14'}             & \mcc{`IVbetadfictsd12'}           & \mcc{`IVpcbetadfisd12'}   \\
tex \% reject $\beta \geqslant 1$     & \mcc{`IVfulladdpercreject12'}     & \mcc{`IVfulladdpercreject13'} & \mcc{`IVfulladdpercreject14'}     & \mcc{`IVfulladdpercrejectct12'}   & \mcc{`IVpcfulladdpercreject12'} \\
tex Med.\ F                           & \mcc{`IVmedFSF12'}                & \mcc{`IVmedFSF13'}            & \mcc{`IVmedFSF14'}                & \mcc{`IVmedFSFct12'}              & \mcc{`IVpcmedFSF12'} \\
tex \mbox{\% reject underid.}         & \mcc{`IVunderidpercreject12'}     & \mcc{`IVunderidpercreject13'} & \mcc{`IVunderidpercreject14'}     & \mcc{`IVunderidpercrejectct12'}   & \mcc{`IVpcunderidpercreject12'} \\
tex Med.\ FS    					  & `IVbetaFSmedian12'                & `IVbetaFSmedian13'            & `IVbetaFSmedian14'                & `IVbetactFSmedian12'              & `IVpcbetaFSmedian12'   \\
tex Med.\ RF    					  & `IVbetaRFmedian12'                & `IVbetaRFmedian13'            & `IVbetaRFmedian14'                & `IVbetactRFmedian12'              & `IVpcbetaRFmedian12'   \\
tex \bottomrule
texdoc close


*************************************************************************
*************************************************************************
* WITH CAPPED BUDGET
*************************************************************************
*************************************************************************
clear all
/* Set path to correct folder */ 
local DISK Nicolas // options: Nicolas, Paddy
if "`DISK'"=="Paddy" {
	cd "C:\Users\Paddy Carter\Dropbox\Development Finance Institutions\Country\Monte Carlo"
}
else if "`DISK'"=="Nicolas" {
	cd "C:\Users\ec1nv\Dropbox\My Documents\My Papers\Development Finance Institutions\Country\Monte Carlo"
	local tablesexport "C:\Users\ec1nv\Dropbox\My Documents\My Papers\Development Finance Institutions\Paper\Tables"
}
else {
	di as error "Incorrect content for local DISK"
	exit
}
set matsize 500


*************************************************************************
* OLS and FE
*************************************************************************
foreach num of numlist 1/6 {
	clear
	capture log close
	log using "./Generated data/OLSFEcapped`num'", replace text
	use "./Generated data/OLSFEcapped`num'.dta"

	
	/* First check if all replications have been successful. */
	egen nummissing = rowmiss(olsbetadfi-maxdbpercnumprojerover2)
	tab nummissing, missing
	count if nummissing == 0
	scalar successfulreps = r(N)
	foreach var of varlist * { 
		replace `var' = . if nummissing != 0
	}


	/* Selected statistics to export to Excel later: */
	/* OLS without pc */
	su olsbetadfi, detail
	scalar olsbetadfimean = r(mean)
	local olsbetadfimean`num': di %4.2f olsbetadfimean
	scalar olsbetadfisd = r(sd)
	local olsbetadfisd`num': di %4.2f olsbetadfisd
	//
	count if olspzeroadd < 0.05
	scalar olszeroaddpercreject = (r(N)/successfulreps)*100
	local olszeroaddpercreject`num': di %5.0g olszeroaddpercreject
	count if olspfulladd < 0.05
	scalar olsfulladdpercreject = (r(N)/successfulreps)*100
	local olsfulladdpercreject`num': di %5.0g olsfulladdpercreject
	//
	su olsr2
	scalar olsr2mean = r(mean)
	/* OLS with pc */
	su olspcbetadfi, detail
	scalar olspcbetadfimean = r(mean)
	local olspcbetadfimean`num': di %4.2f olspcbetadfimean
	scalar olspcbetadfisd = r(sd)
	local olspcbetadfisd`num': di %4.2f olspcbetadfisd
	//
	count if olspcpzeroadd < 0.05
	scalar olspczeroaddpercreject = (r(N)/successfulreps)*100	
	local olspczeroaddpercreject`num': di %5.0g olspczeroaddpercreject
	count if olspcpfulladd < 0.05
	scalar olspcfulladdpercreject = (r(N)/successfulreps)*100
	local olspcfulladdpercreject`num': di %5.0g olspcfulladdpercreject
	//
	su olspcr2
	scalar olspcr2mean = r(mean)
	su olspcnodfir2
	scalar olspcnodfir2mean = r(mean)
	su olspcnodfinotdummiesr2
	scalar olspcnodfinotdummiesr2mean = r(mean)

	/* FE */
	su febetadfi, detail
	scalar febetadfimean = r(mean)
	local febetadfimean`num': di %4.2f febetadfimean
	scalar febetadfisd = r(sd)
	local febetadfisd`num': di %4.2f febetadfisd
	//
	count if fepzeroadd < 0.05
	scalar fezeroaddpercreject=(r(N)/successfulreps)*100
	local fezeroaddpercreject`num': di %5.0g fezeroaddpercreject
	count if fepfulladd < 0.05
	scalar fefulladdpercreject=(r(N)/successfulreps)*100
	local fefulladdpercreject`num': di %5.0g fefulladdpercreject
	//
	su fewr2
	scalar fewr2mean = r(mean)
	/* FE with pc */
	su fepcbetadfi, detail
	scalar fepcbetadfimean = r(mean)
	local fepcbetadfimean`num': di %4.2f fepcbetadfimean
	scalar fepcbetadfisd = r(sd)
	local fepcbetadfisd`num': di %4.2f fepcbetadfisd
	//
	count if fepcpzeroadd < 0.05
	scalar fepczeroaddpercreject=(r(N)/successfulreps)*100
	local fepczeroaddpercreject`num': di %5.0g fepczeroaddpercreject
	count if fepcpfulladd < 0.05
	scalar fepcfulladdpercreject=(r(N)/successfulreps)*100
	local fepcfulladdpercreject`num': di %5.0g fepcfulladdpercreject
	//
	su fepcwr2
	scalar fepcwr2mean = r(mean)
	su fepcnodfiwr2
	scalar fepcnodfiwr2mean = r(mean)
	su fepcnodfinotdummieswr2
	scalar fepcnodfinotdummieswr2mean = r(mean)
	
	/* Omitted variable bias in OLS: */
	/* Coefficient when controlling for number of projects with return over 2. */
	su olsbetadfitrue
	scalar olsbetadfitruemean = r(mean)
	// with pc included
	su olspcbetadfitrue
	scalar olspcbetadfitruemean = r(mean)
	/* Omitted variable bias */ 
	gen double OVB = olsbetanumprojerover2*olsdelta
	su OVB
	scalar olsbiasdfimean = r(mean)
	su olsbetanumprojerover2
	scalar olsbetanumprojerover2mean = r(mean)
	su olsdelta
	scalar olsdeltamean = r(mean)
	su olsdeltapartialledout
	scalar olsdeltapartoutmean = r(mean)
	su olsdeltadenom
	scalar olsdeltadenommean = r(mean)
	su olsdeltanum
	scalar olsdeltanummean = r(mean)
	gen double olsdeltapartoutman = olsdeltanum/olsdeltadenom
	su olsdeltapartoutman
	scalar olsdeltapartoutmanmean = r(mean)
	su covnumprojver2DFIinv
	scalar covnumprojver2DFIinvmean = r(mean)
	su varDFIinv
	scalar varDFIinvmean = r(mean)
	//
	gen double OVBpc = olspcbetanumprojerover2*olspcdelta
	su OVBpc
	scalar olspcbiasdfimean = r(mean)
	su olspcbetanumprojerover2
	scalar olspcbetanumprojerover2mean = r(mean)
	su olspcdelta
	scalar olspcdeltamean = r(mean)
	su olspcbetapctrue
	scalar olspcbetapctruemean = r(mean)
	su olspcdeltapartialledout
	scalar olspcdeltapartoutmean = r(mean)
	su olspcdeltadenom
	scalar olspcdeltadenommean = r(mean)
	su olspcdeltanum
	scalar olspcdeltanummean = r(mean)
	gen double olspcdeltapartoutman = olspcdeltanum/olspcdeltadenom
	su olspcdeltapartoutman
	scalar olspcdeltapartoutmanmean = r(mean)
	
	count if maxdbpercnumprojerover2 >= 1 & maxdbpercnumprojerover2 != .
	scalar countmaxdbpercnumprojerover2exc1 = r(N)
	
	su medinvDFIvsprivate, detail
	scalar medmedinvDFIvsprivate = r(p50)

	scalar empty = .
	scalar number = `num'

	
	// Put statistics in matrix:
	matrix OLSFE_`num' = (number \ olsbetadfimean \ olsbetadfitruemean \ olsbiasdfimean \ olsbetanumprojerover2mean \ olsdeltamean \ olsdeltapartoutmean \ olsdeltapartoutmanmean ///
	\ olsdeltanummean \ olsdeltadenommean \ covnumprojver2DFIinvmean \ varDFIinvmean ///
	\ olsbetadfisd  \ olszeroaddpercreject \ olsfulladdpercreject \ olsr2mean /// 
	\ olspcbetadfimean  \ olspcbetadfitruemean \ olspcbiasdfimean \ olspcbetanumprojerover2mean \ olspcdeltamean \ olspcdeltapartoutmean \ olspcdeltapartoutmanmean /// 
	\ olspcdeltanummean \ olspcdeltadenommean ///
	\ olspcbetapctruemean \ olspcbetadfisd \ olspczeroaddpercreject \ olspcfulladdpercreject \ olspcr2mean ///
	\ olspcnodfir2mean \ olspcnodfinotdummiesr2mean \ empty /// 
	\ febetadfimean \ febetadfisd \ fezeroaddpercreject \ fefulladdpercreject \ fewr2mean /// 
	\ fepcbetadfimean \ fepcbetadfisd \ fepczeroaddpercreject \ fepcfulladdpercreject \ fepcwr2mean \ fepcnodfiwr2mean \ fepcnodfinotdummieswr2mean /// 
	\ empty \ countmaxdbpercnumprojerover2exc1 \ successfulreps \ medmedinvDFIvsprivate)
	matrix list OLSFE_`num'

	log close
}


/* Construct matrices that combine results. */
/* First table: */
foreach num of numlist 1/6 {
	if `num'==1 { 
		matrix tableOLSFE = OLSFE_`num'
	}
	else { 
		matrix tableOLSFE=(tableOLSFE, OLSFE_`num')
	}        
}


/* Export to Excel. */
putexcel set "./Tables/OLSFEtable_capped", replace
putexcel B2 = matrix(tableOLSFE) // starting point of table
//
local row 3
putexcel A`row++' = "OLS DFI coeff. mean"
putexcel A`row++' = "OLS DFI coeff. mean in true model"
putexcel A`row++' = "OLS DFI mean bias manually calculated"
putexcel A`row++' = "OLS # projects er > 2 coeff. mean"
putexcel A`row++' = "Delta coeff. mean"
putexcel A`row++' = "Delta coeff. mean partialled out"
putexcel A`row++' = "Delta coeff. mean partialled out, manually calculated"
putexcel A`row++' = "Delta coeff. numerator mean"
putexcel A`row++' = "Delta coeff. denominator mean"
putexcel A`row++' = "Raw cov. # projects er > 2 and DFI investment mean"
putexcel A`row++' = "Raw var. DFI investment mean"
putexcel A`row++' = "OLS DFI coeff. st. dev."
putexcel A`row++' = "OLS % reject zero additionality"
putexcel A`row++' = "OLS % reject full additionality"
putexcel A`row++' = "OLS R2 mean"
//
putexcel A`row++' = "OLS with pc DFI coeff. mean"
putexcel A`row++' = "OLS with pc DFI coeff. mean in true model"
putexcel A`row++' = "OLS with pc DFI mean bias manually calculated"
putexcel A`row++' = "OLS with pc # projects er > 2 coeff. mean"
putexcel A`row++' = "Delta coeff. mean with pc"
putexcel A`row++' = "Delta coeff. mean partialled out with pc"
putexcel A`row++' = "Delta coeff. mean partialled out, manually calculated, with pc"
putexcel A`row++' = "Delta coeff. with pc numerator mean"
putexcel A`row++' = "Delta coeff. with pc denominator mean"
putexcel A`row++' = "OLS pc coeff. mean in true model"
putexcel A`row++' = "OLS with pc DFI coeff. st. dev."
putexcel A`row++' = "OLS with pc % reject zero additionality"
putexcel A`row++' = "OLS with pc % reject full additionality"
putexcel A`row++' = "OLS with pc R2 mean"
putexcel A`row++' = "OLS with pc no DFI R2 mean"
putexcel A`row++' = "OLS with pc no DFI and no time dummies R2 mean"
//
putexcel A`row++' = ""
//
putexcel A`row++' = "FE DFI coeff. mean"
putexcel A`row++' = "FE DFI coeff. st. dev."
putexcel A`row++' = "FE % reject zero additionality"
putexcel A`row++' = "FE % reject full additionality"
putexcel A`row++' = "FE within R2 mean"
//
putexcel A`row++' = "FE with pc DFI coeff. mean"
putexcel A`row++' = "FE with pc DFI coeff. st. dev."
putexcel A`row++' = "FE with pc % reject zero additionality"
putexcel A`row++' = "FE with pc % reject full additionality"
putexcel A`row++' = "FE with pc within R2 mean"
putexcel A`row++' = "FE with pc no DFI within R2 mean"
putexcel A`row++' = "FE with pc no DFI and no time dummies within R2 mean"
//
putexcel A`row++' = ""
putexcel A`row++' = "Number of datasets where max db exceeds # proj. with er > 2"
putexcel A`row++' = "# successful replications"
putexcel A`row++' = "Med. of med. DFI inv/private"
//	
putexcel B1= "Zero add., random, no pc noise"
putexcel C1= "Zero add., random, noise = 0.5"
putexcel D1= "Zero add., random, noise = 1"
putexcel E1= "Zero add., pclow, no pc noise"
putexcel F1= "Zero add., pclow, noise = 0.5"
putexcel G1= "Zero add., pclow, noise = 1"


/* Now generate table to export to TeX, using texdoc. */
/* Random selection */
texdoc init "`tablesexport'/OLSFEexport_random_capped.tex", replace force
tex  									 & \mcolsfe{(1)} 				 & \mcolsfe{(2)} 				   & \mcolsfe{(3)} 						   & \mcolsfe{(4)} 					 \\
tex $\beta$                              & \mcolsfe{0}                   & \mcolsfe{0}                     & \mcolsfe{0}                           & \mcolsfe{0}                     \\
tex $\mathit{pc}$                        & \mcolsfe{excl.}               & \mcolsfe{$\sigma_m^{2} = 1$}    & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}} & \mcolsfe{$\sigma_m^{2} = 0$}    \\
tex \cmidrule{1-5}
tex Mean $\widehat{\beta}_{OLS}$	     & `olsbetadfimean1'             & `olspcbetadfimean3'             & `olspcbetadfimean2'                   & `olspcbetadfimean1'             \\
tex Std.\ dev.\	                         & `olsbetadfisd1'               & `olspcbetadfisd3'               & `olspcbetadfisd2'                     & `olspcbetadfisd1'               \\
tex \mbox{\% reject $\beta \leqslant 0$} & \mcc{`olszeroaddpercreject1'} & \mcc{`olspczeroaddpercreject3'} & \mcc{`olspczeroaddpercreject2'}       & \mcc{`olspczeroaddpercreject1'} \\
tex Mean $\widehat{\beta}_{FE}$	         & `febetadfimean1'              & `fepcbetadfimean3'              & `fepcbetadfimean2'                    & `fepcbetadfimean1'              \\
tex Std.\ dev.\	                         & `febetadfisd1'                & `fepcbetadfisd3'                & `fepcbetadfisd2'                      & `fepcbetadfisd1'                \\
tex \mbox{\% reject $\beta \leqslant 0$} & \mcc{`fezeroaddpercreject1'}  & \mcc{`fepczeroaddpercreject3'}  & \mcc{`fepczeroaddpercreject2'}        & \mcc{`fepczeroaddpercreject1'}  \\
tex \bottomrule
texdoc close


/* pclow selection */
texdoc init "`tablesexport'/OLSFEexport_pclow_capped.tex", replace force
tex  									 & \mcolsfe{(1)} 				 & \mcolsfe{(2)} 				   & \mcolsfe{(3)} 						   & \mcolsfe{(4)} 					 \\
tex $\beta$                              & \mcolsfe{0}                   & \mcolsfe{0}                     & \mcolsfe{0}                           & \mcolsfe{0}                     \\
tex $\mathit{pc}$                        & \mcolsfe{excl.}               & \mcolsfe{$\sigma_m^{2} = 1$}    & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}} & \mcolsfe{$\sigma_m^{2} = 0$}    \\
tex \cmidrule{1-5}
tex Mean $\widehat{\beta}_{OLS}$	     & `olsbetadfimean4'             & `olspcbetadfimean6'             & `olspcbetadfimean5'                   & `olspcbetadfimean4'             \\
tex Std.\ dev.\	                         & `olsbetadfisd4'               & `olspcbetadfisd6'               & `olspcbetadfisd5'                     & `olspcbetadfisd4'               \\
tex \mbox{\% reject $\beta \leqslant 0$} & \mcc{`olszeroaddpercreject4'} & \mcc{`olspczeroaddpercreject6'} & \mcc{`olspczeroaddpercreject5'}       & \mcc{`olspczeroaddpercreject4'} \\
tex Mean $\widehat{\beta}_{FE}$	         & `febetadfimean4'              & `fepcbetadfimean6'              & `fepcbetadfimean5'                    & `fepcbetadfimean4'              \\
tex Std.\ dev.\	                         & `febetadfisd4'                & `fepcbetadfisd6'                & `fepcbetadfisd5'                      & `fepcbetadfisd4'                \\
tex \mbox{\% reject $\beta \leqslant 0$} & \mcc{`fezeroaddpercreject4'}  & \mcc{`fepczeroaddpercreject6'}  & \mcc{`fepczeroaddpercreject5'}        & \mcc{`fepczeroaddpercreject4'}  \\
tex \bottomrule
texdoc close


*************************************************************************
* GMM WITH ZERO ADDITIONALITY
*************************************************************************
foreach num of numlist 1/6 { // start loop over generated datasets/experiments
	clear
	capture log close
	log using "./Generated data/GMMzeroaddcapped`num'", replace text
	use "./Generated data/GMMzeroaddcapped`num'.dta"

	
	/* First check if all replications have been successful. */
	egen nummissing = rowmiss(betadfi1-finalnumprojerover2)
	tab nummissing, missing
	count if nummissing == 0
	scalar successfulreps = r(N)
	foreach var of varlist * { 
		replace `var' = . if nummissing != 0
	}

	
	/* Selected statistics to export to Excel later: */
	foreach model of numlist 1/8 { // start loop over models estimated within each dataset

		foreach wpc in "" "wpc" { // loop over statistics without and with control for pc

			/* Results */
			su betadfi`wpc'`model', detail
			scalar DFIinv`wpc'`model'mean = r(mean)
			scalar DFIinv`wpc'`model'med = r(p50)
			local sysGMM`wpc'`model'betadfimedian`num': di %4.2f DFIinv`wpc'`model'med				
			scalar DFIinv`wpc'`model'sd = r(sd)
			local sysGMM`wpc'`model'betadfisd`num': di %4.2f DFIinv`wpc'`model'sd							
			//
			count if pzeroadd`wpc'`model' < 0.05
			scalar pzeroaddpercreject`wpc'`model' = (r(N)/successfulreps)*100
			local sysGMMzeroaddpercreject`wpc'`model'`num': di %5.0g pzeroaddpercreject`wpc'`model'
			//
			count if pfulladd`wpc'`model' < 0.05
			scalar pfulladdpercreject`wpc'`model' = (r(N)/successfulreps)*100
			//
			capture noisily su betalagdep`wpc'`model', detail
			scalar lagdep`wpc'`model'mean = r(mean)
			scalar lagdep`wpc'`model'med = r(p50)
			scalar lagdep`wpc'`model'sd = r(sd)
			
			/* Diagnostic checks */
			capture noisily su numinstr`wpc'`model'
			scalar numinstr`wpc'`model' = r(mean)
			// Calculate percentage of diagnostic tests that "pass" (i.e. don't suggest a problem, at a 10% significance level)
			capture noisily count if m1`wpc'`model' < 0 & m1p`wpc'`model' < 0.1 
			scalar m1percpass`wpc'`model' = (r(N)/successfulreps)*100
			if _rc == 111 {
				scalar m1percpass`wpc'`model' = .			
			}			
			
			capture noisily count if m2p`wpc'`model' > 0.1 & m2p`wpc'`model' != .
			scalar m2percpass`wpc'`model' = (r(N)/successfulreps)*100
			if _rc == 111 {
				scalar m2percpass`wpc'`model' = .			
			}
			
			capture noisily count if hansp`wpc'`model' > 0.1 & hansp`wpc'`model' != .
			scalar hansenpercpass`wpc'`model' = (r(N)/successfulreps)*100
			if _rc == 111 {
				scalar hansenpercpass`wpc'`model' = .			
			}
			local sysGMMhansenpercpass`wpc'`model'`num': di %5.0g hansenpercpass`wpc'`model'
			
			capture noisily count if sargp`wpc'`model' > 0.1 & sargp`wpc'`model' != .
			scalar sarganpercpass`wpc'`model' = (r(N)/successfulreps)*100
			if _rc == 111 {
				scalar sarganpercpass`wpc'`model' = .			
			}
			
			foreach moment in lev lagdep DFIinvdiff DFIinvlev { // pc moment condition follows later, outside of wpc loop
				capture noisily count if diffHp_`moment'`wpc'`model' > 0.1 & diffHp_`moment'`wpc'`model' != .
				scalar hansenpercpass`moment'`wpc'`model' = (r(N)/successfulreps)*100
				if _rc == 111 {
					scalar hansenpercpass`moment'`wpc'`model' = .			
				}
			}
			
			capture noisily su condFDFI`wpc'`model', detail
			scalar condFDFI`wpc'`model'med = r(p50)
			local sysGMMcondFDFI`wpc'`model'med`num': di %5.0g condFDFI`wpc'`model'med
						
			capture noisily count if condFDFIp`wpc'`model' < 0.05
			scalar condFDFIpercrejunderid`wpc'`model' = (r(N)/successfulreps)*100
			if _rc == 111 {
				scalar condFDFIpercrejunderid`wpc'`model' = .			
			}
			local sysGMMcondFDFIpercrej`wpc'`model'`num': di %5.0g condFDFIpercrejunderid`wpc'`model'
			
		} // close loop over statistics without and with control for pc 
		
		/* Statistic that only exists in the model with pc */
		capture noisily count if diffHp_pc`model' > 0.1 & diffHp_pc`model' != .
		scalar hansenpercpasspc`model' = (r(N)/successfulreps)*100
		if _rc == 111 {
			scalar hansenpercpasspc`model' = .			
		}

	} // close loop over models estimated within each dataset

	
	/* IV estimation (first statistics that show up in 6, 8) */
	foreach model of numlist 6 8 { // start loop over models 6 8
		foreach wpc in "" "wpc" { // loop over statistics without and with control for pc
			capture noisily su FSrobustF`wpc'`model', detail
			scalar FSrobF`wpc'`model'med = r(p50)
		} // close loop over statistics without and with control for pc 
		// some statistics only show up without pc
		capture noisily su sdu`model', detail
		scalar sdu`model'med = r(p50)

		capture noisily su sdx`model', detail
		scalar sdx`model'med = r(p50)
	} // close loop over models 6 8	
	

	/* Statistics that don't show up for both models (so take them outside the 6 8 loop): */
	// Statistics showing up in 6
	foreach model of numlist 6 {
		foreach wpc in "" "wpc" { // first loop over statistics that exist both without and with control for pc
			capture noisily su FSbetaL2DFI`wpc'`model', detail
			scalar FSbetaL2DFI`wpc'`model'med = r(p50)

			capture noisily su OVbetaL2DFI`wpc'`model', detail
			scalar OVbetaL2DFI`wpc'`model'med = r(p50)
			
		} // end wpc loop
		// some statistics only show up with pc or without pc
		capture noisily su corrL2DFIu`model', detail
		scalar corrL2DFIu`model'med = r(p50)

		capture noisily su corrL2DFIx`model', detail
		scalar corrL2DFIx`model'med = r(p50)	
		
		capture noisily su FSbetaL2pc`model', detail
		scalar FSbetaL2pc`model'med = r(p50)

		capture noisily su OVbetaL2pc`model', detail
		scalar OVbetaL2pc`model'med = r(p50)
	
		capture noisily su corrL2pcu`model', detail
		scalar corrL2pcu`model'med = r(p50)

		capture noisily su corrL2pcx`model', detail
		scalar corrL2pcx`model'med = r(p50)
	} // end loop over model 6


	// now for statistics showing up in 8
	foreach model of numlist 8 { // start loop over model 8
		foreach wpc in "" "wpc" { // first loop over statistics that exist without and with control for pc
			capture noisily su FSbetaDLDFI`wpc'`model', detail
			scalar FSbetaDLDFI`wpc'`model'med = r(p50)

			capture noisily su OVbetaDLDFI`wpc'`model', detail
			scalar OVbetaDLDFI`wpc'`model'med = r(p50)

		} // close loop over statistics without and with control for pc 
		// some statistics that only show up with pc or without pc
		capture noisily su corrDLDFIu`model', detail
		scalar corrDLDFIu`model'med = r(p50)
		
		capture noisily su corrDLDFIx`model', detail
		scalar corrDLDFIx`model'med = r(p50)

		capture noisily su FSbetaDLpc`model', detail
		scalar FSbetaDLpc`model'med = r(p50)
					
		capture noisily su OVbetaDLpc`model', detail
		scalar OVbetaDLpc`model'med = r(p50)

		capture noisily su corrDLpcu`model', detail
		scalar corrDLpcu`model'med = r(p50)

		capture noisily su corrDLpcx`model', detail
		scalar corrDLpcx`model'med = r(p50)
	} // end loop over model 8

		
	/* Manually calculate bias for some of the models: */
	// Biases showing up in 6
	foreach model of numlist 6 {
		// bias based on DFI instrument
		gen double DFIbiasDFIinv`model' = (corrL2DFIu`model'/corrL2DFIx`model')*(sdu`model'/sdx`model')
		su DFIbiasDFIinv`model', detail
		scalar DFIbiasDFIinv`model'mean = r(mean)
		scalar DFIbiasDFIinv`model'med = r(p50)
	} // end loop over models 6


	// Biases showing up in 8
	foreach model of numlist 8 {
		// bias based on DFI instrument
		gen double DFIbiasDFIinv`model' = (corrDLDFIu`model'/corrDLDFIx`model')*(sdu`model'/sdx`model')
		su DFIbiasDFIinv`model', detail
		scalar DFIbiasDFIinv`model'mean = r(mean)
		scalar DFIbiasDFIinv`model'med = r(p50)
	} // end loop over model 8
	
	count if maxdbpercnumprojerover2 >= 1 & maxdbpercnumprojerover2 != .
	scalar countmaxdbpercnumprojerover2exc1 = r(N)
	
	su medinvDFIvsprivate, detail
	scalar medmedinvDFIvsprivate = r(p50)		

	scalar empty = .
	scalar number = `num'

	// Put statistics in matrix:
	matrix GMMzeroadd_`num' = (number \ empty \ empty \ DFIinv1mean \ DFIinv1med \ DFIinv1sd /// 
	\ pzeroaddpercreject1 \ pfulladdpercreject1 ///
	\ lagdep1mean \ lagdep1med \ lagdep1sd \ numinstr1 \ m1percpass1 ///
	\ m2percpass1 \ hansenpercpass1 \ sarganpercpass1 \ hansenpercpasslev1 \ hansenpercpasslagdep1 /// 
	\ hansenpercpassDFIinvdiff1 \ hansenpercpassDFIinvlev1 \ condFDFI1med ///
	\ condFDFIpercrejunderid1 ///
	\ empty ///
	\ DFIinvwpc1mean \ DFIinvwpc1med \ DFIinvwpc1sd \ pzeroaddpercrejectwpc1 \ pfulladdpercrejectwpc1 ///
	\ lagdepwpc1mean \ lagdepwpc1med \ lagdepwpc1sd \ numinstrwpc1 \ m1percpasswpc1 ///
	\ m2percpasswpc1 \ hansenpercpasswpc1 \ sarganpercpasswpc1 \ hansenpercpasslevwpc1 \ hansenpercpasslagdepwpc1 /// 
	\ hansenpercpassDFIinvdiffwpc1 \ hansenpercpassDFIinvlevwpc1 \ hansenpercpasspc1 \ condFDFIwpc1med ///
	\ condFDFIpercrejunderidwpc1 ///
	\ empty \ empty ///
	\ DFIinv2mean \ DFIinv2med \ DFIinv2sd \ pzeroaddpercreject2 \ pfulladdpercreject2 ///
	\ lagdep2mean \ lagdep2med \ lagdep2sd \ numinstr2 \ m1percpass2 ///
	\ m2percpass2 \ hansenpercpass2 \ sarganpercpass2 \ hansenpercpasslev2 \ hansenpercpasslagdep2 /// 
	\ hansenpercpassDFIinvdiff2 \ hansenpercpassDFIinvlev2 \ condFDFI2med ///
	\ condFDFIpercrejunderid2 ///
	\ empty ///
	\ DFIinvwpc2mean \ DFIinvwpc2med \ DFIinvwpc2sd \ pzeroaddpercrejectwpc2 \ pfulladdpercrejectwpc2 ///
	\ lagdepwpc2mean \ lagdepwpc2med \ lagdepwpc2sd \ numinstrwpc2 \ m1percpasswpc2 ///
	\ m2percpasswpc2 \ hansenpercpasswpc2 \ sarganpercpasswpc2 \ hansenpercpasslevwpc2 \ hansenpercpasslagdepwpc2 /// 
	\ hansenpercpassDFIinvdiffwpc2 \ hansenpercpassDFIinvlevwpc2 \ hansenpercpasspc2 \ condFDFIwpc2med ///
	\ condFDFIpercrejunderidwpc2 ///
	\ empty \ empty ///
	\ DFIinv3mean \ DFIinv3med \ DFIinv3sd \ pzeroaddpercreject3 \ pfulladdpercreject3 ///
	\ lagdep3mean \ lagdep3med \ lagdep3sd \ numinstr3 \ m1percpass3 ///
	\ m2percpass3 \ hansenpercpass3 \ sarganpercpass3 \ hansenpercpasslev3 \ hansenpercpasslagdep3 /// 
	\ hansenpercpassDFIinvdiff3 \ hansenpercpassDFIinvlev3 \ condFDFI3med ///
	\ condFDFIpercrejunderid3 ///
	\ empty ///
	\ DFIinvwpc3mean \ DFIinvwpc3med \ DFIinvwpc3sd \ pzeroaddpercrejectwpc3 \ pfulladdpercrejectwpc3 ///
	\ lagdepwpc3mean \ lagdepwpc3med \ lagdepwpc3sd \ numinstrwpc3 \ m1percpasswpc3 ///
	\ m2percpasswpc3 \ hansenpercpasswpc3 \ sarganpercpasswpc3 \ hansenpercpasslevwpc3 \ hansenpercpasslagdepwpc3 /// 
	\ hansenpercpassDFIinvdiffwpc3 \ hansenpercpassDFIinvlevwpc3 \ hansenpercpasspc3 \ condFDFIwpc3med ///
	\ condFDFIpercrejunderidwpc3 ///
	\ empty \ empty ///
	\ DFIinv4mean \ DFIinv4med \ DFIinv4sd \ pzeroaddpercreject4 \ pfulladdpercreject4 ///
	\ lagdep4mean \ lagdep4med \ lagdep4sd \ numinstr4 \ m1percpass4 ///
	\ m2percpass4 \ hansenpercpass4 \ sarganpercpass4 \ hansenpercpasslev4 \ hansenpercpasslagdep4 /// 
	\ hansenpercpassDFIinvdiff4 \ hansenpercpassDFIinvlev4 \ condFDFI4med ///
	\ condFDFIpercrejunderid4 ///
	\ empty ///
	\ DFIinvwpc4mean \ DFIinvwpc4med \ DFIinvwpc4sd \ pzeroaddpercrejectwpc4 \ pfulladdpercrejectwpc4 ///
	\ lagdepwpc4mean \ lagdepwpc4med \ lagdepwpc4sd \ numinstrwpc4 \ m1percpasswpc4 ///
	\ m2percpasswpc4 \ hansenpercpasswpc4 \ sarganpercpasswpc4 \ hansenpercpasslevwpc4 \ hansenpercpasslagdepwpc4 /// 
	\ hansenpercpassDFIinvdiffwpc4 \ hansenpercpassDFIinvlevwpc4 \ hansenpercpasspc4 \ condFDFIwpc4med ///
	\ condFDFIpercrejunderidwpc4 ///
	\ empty \ empty ///
	\ DFIinv5mean \ DFIinv5med \ DFIinv5sd \ pzeroaddpercreject5 \ pfulladdpercreject5 ///
	\ lagdep5mean \ lagdep5med \ lagdep5sd \ numinstr5 \ m1percpass5 ///
	\ m2percpass5 \ hansenpercpass5 \ sarganpercpass5 \ hansenpercpasslev5 \ hansenpercpasslagdep5 /// 
	\ hansenpercpassDFIinvdiff5 \ hansenpercpassDFIinvlev5 \ condFDFI5med ///
	\ condFDFIpercrejunderid5 ///
	\ empty ///
	\ DFIinvwpc5mean \ DFIinvwpc5med \ DFIinvwpc5sd \ pzeroaddpercrejectwpc5 \ pfulladdpercrejectwpc5 ///
	\ lagdepwpc5mean \ lagdepwpc5med \ lagdepwpc5sd \ numinstrwpc5 \ m1percpasswpc5 ///
	\ m2percpasswpc5 \ hansenpercpasswpc5 \ sarganpercpasswpc5 \ hansenpercpasslevwpc5 \ hansenpercpasslagdepwpc5 /// 
	\ hansenpercpassDFIinvdiffwpc5 \ hansenpercpassDFIinvlevwpc5 \ hansenpercpasspc5 \ condFDFIwpc5med ///
	\ condFDFIpercrejunderidwpc5 ///
	\ empty \ empty)

	
	matrix GMMzeroadd_`num' = (GMMzeroadd_`num' \ DFIinv6mean \ DFIinv6med \ DFIinv6sd \ pzeroaddpercreject6 \ pfulladdpercreject6 \ FSrobF6med ///
	\ FSbetaL2DFI6med \ OVbetaL2DFI6med \ corrL2DFIu6med \ corrL2DFIx6med \ sdu6med \ sdx6med \ DFIbiasDFIinv6mean \ DFIbiasDFIinv6med ///
	\ empty ///
	\ DFIinvwpc6mean \ DFIinvwpc6med \ DFIinvwpc6sd \ pzeroaddpercrejectwpc6 \ pfulladdpercrejectwpc6 \ FSrobFwpc6med ///
	\ FSbetaL2DFIwpc6med \ FSbetaL2pc6med \ OVbetaL2DFIwpc6med \ OVbetaL2pc6med /// 
	\ empty \ empty ///
	\ DFIinv7mean \ DFIinv7med \ DFIinv7sd \ pzeroaddpercreject7 \ pfulladdpercreject7 ///
	\ lagdep7mean \ lagdep7med \ lagdep7sd \ numinstr7 \ m1percpass7 ///
	\ m2percpass7 \ hansenpercpass7 \ sarganpercpass7 \ hansenpercpasslev7 \ hansenpercpasslagdep7 /// 
	\ hansenpercpassDFIinvdiff7 \ hansenpercpassDFIinvlev7 \ condFDFI7med ///
	\ condFDFIpercrejunderid7 ///
	\ empty ///
	\ DFIinvwpc7mean \ DFIinvwpc7med \ DFIinvwpc7sd \ pzeroaddpercrejectwpc7 \ pfulladdpercrejectwpc7 ///
	\ lagdepwpc7mean \ lagdepwpc7med \ lagdepwpc7sd \ numinstrwpc7 \ m1percpasswpc7 ///
	\ m2percpasswpc7 \ hansenpercpasswpc7 \ sarganpercpasswpc7 \ hansenpercpasslevwpc7 \ hansenpercpasslagdepwpc7 /// 
	\ hansenpercpassDFIinvdiffwpc7 \ hansenpercpassDFIinvlevwpc7 \ hansenpercpasspc7 \ condFDFIwpc7med ///
	\ condFDFIpercrejunderidwpc7 ///
	\ empty \ empty ///
	\ DFIinv8mean \ DFIinv8med \ DFIinv8sd \ pzeroaddpercreject8 \ pfulladdpercreject8 \ FSrobF8med ///
	\ FSbetaDLDFI8med \ OVbetaDLDFI8med \ corrDLDFIu8med \ corrDLDFIx8med \ sdu8med \ sdx8med ///
	\ DFIbiasDFIinv8mean \ DFIbiasDFIinv8med ///
	\ empty ///
	\ DFIinvwpc8mean \ DFIinvwpc8med \ DFIinvwpc8sd \ pzeroaddpercrejectwpc8 \ pfulladdpercrejectwpc8 \ FSrobFwpc8med ///
	\ FSbetaDLDFIwpc8med \ FSbetaDLpc8med \ OVbetaDLDFIwpc8med \ OVbetaDLpc8med /// 
	\ empty \ countmaxdbpercnumprojerover2exc1 \ successfulreps \ medmedinvDFIvsprivate)
			
	matrix list GMMzeroadd_`num'

log close
} // close loop over generated datasets/experiments


/* Construct matrices that combine results. */
/* First table: */
foreach num of numlist 1/6 {
	if `num'==1 { 
		matrix tableGMMzeroadd = GMMzeroadd_`num'
	}
	else { 
		matrix tableGMMzeroadd=(tableGMMzeroadd, GMMzeroadd_`num')
	}        
}


/* Export to Excel and clean up tables. */
/* First table: */
putexcel set "./Tables/GMMzeroaddtable_capped", replace
putexcel B2 = matrix(tableGMMzeroadd) // starting point of table
//
local row 3
//
putexcel A`row++' = "MODEL 1: SYSTEM GMM, STATIC MODEL, 1 LAG"
putexcel A`row++' = "WITHOUT PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "Lag dep coeff. mean"
putexcel A`row++' = "Lag dep coeff. median"
putexcel A`row++' = "Lag dep coeff. st. dev."
putexcel A`row++' = "# instruments"
putexcel A`row++' = "m1 % pass"
putexcel A`row++' = "m2 % pass"
putexcel A`row++' = "Hansen % pass"
putexcel A`row++' = "Sargan % pass"
putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
putexcel A`row++' = "Conditional F median"
putexcel A`row++' = "Conditional F % reject underidentification"
//
putexcel A`row++' = "WITH PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "Lag dep coeff. mean"
putexcel A`row++' = "Lag dep coeff. median"
putexcel A`row++' = "Lag dep coeff. st. dev."
putexcel A`row++' = "# instruments"
putexcel A`row++' = "m1 % pass"
putexcel A`row++' = "m2 % pass"
putexcel A`row++' = "Hansen % pass"
putexcel A`row++' = "Sargan % pass"
putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen pc % pass"
putexcel A`row++' = "Conditional F median"
putexcel A`row++' = "Conditional F % reject underidentification"
//
//
putexcel A`row++' = "MODEL 2: SYSTEM GMM, WITH LDV, 1 LAG"
putexcel A`row++' = "WITHOUT PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "Lag dep coeff. mean"
putexcel A`row++' = "Lag dep coeff. median"
putexcel A`row++' = "Lag dep coeff. st. dev."
putexcel A`row++' = "# instruments"
putexcel A`row++' = "m1 % pass"
putexcel A`row++' = "m2 % pass"
putexcel A`row++' = "Hansen % pass"
putexcel A`row++' = "Sargan % pass"
putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
putexcel A`row++' = "Conditional F median"
putexcel A`row++' = "Conditional F % reject underidentification"
//
putexcel A`row++' = "WITH PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "Lag dep coeff. mean"
putexcel A`row++' = "Lag dep coeff. median"
putexcel A`row++' = "Lag dep coeff. st. dev."
putexcel A`row++' = "# instruments"
putexcel A`row++' = "m1 % pass"
putexcel A`row++' = "m2 % pass"
putexcel A`row++' = "Hansen % pass"
putexcel A`row++' = "Sargan % pass"
putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen pc % pass"
putexcel A`row++' = "Conditional F median"
putexcel A`row++' = "Conditional F % reject underidentification"
//
//
putexcel A`row++' = "MODEL 3: SYSTEM GMM, STATIC MODEL, 4 LAGS"
putexcel A`row++' = "WITHOUT PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "Lag dep coeff. mean"
putexcel A`row++' = "Lag dep coeff. median"
putexcel A`row++' = "Lag dep coeff. st. dev."
putexcel A`row++' = "# instruments"
putexcel A`row++' = "m1 % pass"
putexcel A`row++' = "m2 % pass"
putexcel A`row++' = "Hansen % pass"
putexcel A`row++' = "Sargan % pass"
putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
putexcel A`row++' = "Conditional F median"
putexcel A`row++' = "Conditional F % reject underidentification"
//
putexcel A`row++' = "WITH PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "Lag dep coeff. mean"
putexcel A`row++' = "Lag dep coeff. median"
putexcel A`row++' = "Lag dep coeff. st. dev."
putexcel A`row++' = "# instruments"
putexcel A`row++' = "m1 % pass"
putexcel A`row++' = "m2 % pass"
putexcel A`row++' = "Hansen % pass"
putexcel A`row++' = "Sargan % pass"
putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen pc % pass"
putexcel A`row++' = "Conditional F median"
putexcel A`row++' = "Conditional F % reject underidentification"
//
//
putexcel A`row++' = "MODEL 4: SYSTEM GMM, WITH LDV, 4 LAGS"
putexcel A`row++' = "WITHOUT PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "Lag dep coeff. mean"
putexcel A`row++' = "Lag dep coeff. median"
putexcel A`row++' = "Lag dep coeff. st. dev."
putexcel A`row++' = "# instruments"
putexcel A`row++' = "m1 % pass"
putexcel A`row++' = "m2 % pass"
putexcel A`row++' = "Hansen % pass"
putexcel A`row++' = "Sargan % pass"
putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
putexcel A`row++' = "Conditional F median"
putexcel A`row++' = "Conditional F % reject underidentification"
//
putexcel A`row++' = "WITH PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "Lag dep coeff. mean"
putexcel A`row++' = "Lag dep coeff. median"
putexcel A`row++' = "Lag dep coeff. st. dev."
putexcel A`row++' = "# instruments"
putexcel A`row++' = "m1 % pass"
putexcel A`row++' = "m2 % pass"
putexcel A`row++' = "Hansen % pass"
putexcel A`row++' = "Sargan % pass"
putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen pc % pass"
putexcel A`row++' = "Conditional F median"
putexcel A`row++' = "Conditional F % reject underidentification"
//
//
putexcel A`row++' = "MODEL 5: DIFFERENCE GMM, STATIC MODEL, 1 LAG"
putexcel A`row++' = "WITHOUT PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "Lag dep coeff. mean"
putexcel A`row++' = "Lag dep coeff. median"
putexcel A`row++' = "Lag dep coeff. st. dev."
putexcel A`row++' = "# instruments"
putexcel A`row++' = "m1 % pass"
putexcel A`row++' = "m2 % pass"
putexcel A`row++' = "Hansen % pass"
putexcel A`row++' = "Sargan % pass"
putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
putexcel A`row++' = "Conditional F median"
putexcel A`row++' = "Conditional F % reject underidentification"
//
putexcel A`row++' = "WITH PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "Lag dep coeff. mean"
putexcel A`row++' = "Lag dep coeff. median"
putexcel A`row++' = "Lag dep coeff. st. dev."
putexcel A`row++' = "# instruments"
putexcel A`row++' = "m1 % pass"
putexcel A`row++' = "m2 % pass"
putexcel A`row++' = "Hansen % pass"
putexcel A`row++' = "Sargan % pass"
putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen pc % pass"
putexcel A`row++' = "Conditional F median"
putexcel A`row++' = "Conditional F % reject underidentification"
//
//
putexcel A`row++' = "MODEL 6: IV ON DIFFERENCED EQN., STATIC MODEL, 1 LAG"
putexcel A`row++' = "WITHOUT PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "FS robust F median"
putexcel A`row++' = "FS coeff. L2 DFI inv. median"
putexcel A`row++' = "OV coeff. L2 DFI inv. median"
putexcel A`row++' = "Corr(L2 DFI inv.,du) median"
putexcel A`row++' = "Corr(L2 DFI inv.,dx) median"
putexcel A`row++' = "St. dev. du median"
putexcel A`row++' = "St. dev. dx median"
putexcel A`row++' = "Mean bias based on DFI inv. instr."
putexcel A`row++' = "Median bias based on DFI inv. instr."
//
putexcel A`row++' = "WITH PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "FS robust F median"
putexcel A`row++' = "FS coeff. L2 DFI inv. median"
putexcel A`row++' = "FS coeff. L2 pc median"
putexcel A`row++' = "OV coeff. L2 DFI inv. median"
putexcel A`row++' = "OV coeff. L2 pc median"
//
//
putexcel A`row++' = "MODEL 7: LEVELS GMM, STATIC MODEL, 1 LAG"
putexcel A`row++' = "WITHOUT PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "Lag dep coeff. mean"
putexcel A`row++' = "Lag dep coeff. median"
putexcel A`row++' = "Lag dep coeff. st. dev."
putexcel A`row++' = "# instruments"
putexcel A`row++' = "m1 % pass"
putexcel A`row++' = "m2 % pass"
putexcel A`row++' = "Hansen % pass"
putexcel A`row++' = "Sargan % pass"
putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
putexcel A`row++' = "Conditional F median"
putexcel A`row++' = "Conditional F % reject underidentification"
//
putexcel A`row++' = "WITH PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "Lag dep coeff. mean"
putexcel A`row++' = "Lag dep coeff. median"
putexcel A`row++' = "Lag dep coeff. st. dev."
putexcel A`row++' = "# instruments"
putexcel A`row++' = "m1 % pass"
putexcel A`row++' = "m2 % pass"
putexcel A`row++' = "Hansen % pass"
putexcel A`row++' = "Sargan % pass"
putexcel A`row++' = "Diff.-in-Hansen level eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen lag dep % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI diff. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen DFI lev. eqn. % pass"
putexcel A`row++' = "Diff.-in-Hansen pc % pass"
putexcel A`row++' = "Conditional F median"
putexcel A`row++' = "Conditional F % reject underidentification"
//
//
putexcel A`row++' = "MODEL 8: IV ON LEVELS EQN, STATIC MODEL, 1 LAG"
putexcel A`row++' = "WITHOUT PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "FS robust F median"
putexcel A`row++' = "FS coeff. DL DFI inv. median"
putexcel A`row++' = "OV coeff. DL DFI inv. median"
putexcel A`row++' = "Corr(DL DFI inv.,u) median"
putexcel A`row++' = "Corr(DL DFI inv.,x) median"
putexcel A`row++' = "St. dev. u median"
putexcel A`row++' = "St. dev. x median"
putexcel A`row++' = "Mean bias based on DFI inv. instr."
putexcel A`row++' = "Median bias based on DFI inv. instr."
//
putexcel A`row++' = "WITH PC"
putexcel A`row++' = "DFI coeff. mean"
putexcel A`row++' = "DFI coeff. median"
putexcel A`row++' = "DFI coeff. st. dev."
putexcel A`row++' = "% reject zero additionality"
putexcel A`row++' = "% reject full additionality"
putexcel A`row++' = "FS robust F median"
putexcel A`row++' = "FS coeff. DL DFI inv. median"
putexcel A`row++' = "FS coeff. DL pc median"
putexcel A`row++' = "OV coeff. DL DFI inv. median"
putexcel A`row++' = "OV coeff. DL pc median"
//
putexcel A`row++' = " "
putexcel A`row++' = "Number of datasets where max db exceeds # proj. with er > 2"
putexcel A`row++' = "# successful replications"
putexcel A`row++' = "Med. of med. DFI inv/private"
//
putexcel B1= "No noise in pc"
putexcel C1= "Noise 0.5"
putexcel D1= "Noise 1"
putexcel E1= "pc mean closer, noise 0.5"
putexcel F1= "pc mean = 2, noise 0.5"
putexcel G1= "fixed types, noise 0.5"


/* Now generate table to export to TeX, using texdoc. */
/* Baseline table. */
texdoc init "`tablesexport'/GMMexport_zeroadd_capped.tex", replace force
tex  								  & \mcolsfe{(1)} 				      & \mcolsfe{(2)} 				         & \mcolsfe{(3)} 						 & \mcolsfe{(4)} 					    & \mcolsfe{(5)} 				    & \mcolsfe{(6)} 				       & \mcolsfe{(7)} 						   & \mcolsfe{(8)} \\
tex LDV                               & \mcolsfe{no}                      & \mcolsfe{no}                         & \mcolsfe{no}                          & \mcolsfe{no}                         & \mcolsfe{yes}                     & \mcolsfe{yes}                        & \mcolsfe{yes}                         & \mcolsfe{yes} \\
tex $\mathit{pc}$                     & \mcolsfe{excl.}                   & \mcolsfe{$\sigma_m^{2} = 1$}         & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}} & \mcolsfe{$\sigma_m^{2} = 0$}         & \mcolsfe{excl.}                   & \mcolsfe{$\sigma_m^{2} = 1$}         & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}} & \mcolsfe{$\sigma_m^{2} = 0$} \\
tex \cmidrule{1-9}
tex Med.\ $\widehat{\beta}_{sysGMM}$  & `sysGMM1betadfimedian1'           & `sysGMMwpc1betadfimedian3'           & `sysGMMwpc1betadfimedian2'            & `sysGMMwpc1betadfimedian1'           & `sysGMM2betadfimedian1'           & `sysGMMwpc2betadfimedian3'           & `sysGMMwpc2betadfimedian2'            & `sysGMMwpc2betadfimedian1' \\
tex Std.\ dev.\	                      & `sysGMM1betadfisd1'               & `sysGMMwpc1betadfisd3'               & `sysGMMwpc1betadfisd2'                & `sysGMMwpc1betadfisd1'               & `sysGMM2betadfisd1'               & `sysGMMwpc2betadfisd3'               & `sysGMMwpc2betadfisd2'                & `sysGMMwpc2betadfisd1' \\
tex \% reject $\beta \leqslant 0$     & \mcc{`sysGMMzeroaddpercreject11'} & \mcc{`sysGMMzeroaddpercrejectwpc13'} & \mcc{`sysGMMzeroaddpercrejectwpc12'}  & \mcc{`sysGMMzeroaddpercrejectwpc11'} & \mcc{`sysGMMzeroaddpercreject21'} & \mcc{`sysGMMzeroaddpercrejectwpc23'} & \mcc{`sysGMMzeroaddpercrejectwpc22'}  & \mcc{`sysGMMzeroaddpercrejectwpc21'} \\
tex Hansen \% pass                    & \mcc{`sysGMMhansenpercpass11'}    & \mcc{`sysGMMhansenpercpasswpc13'}    & \mcc{`sysGMMhansenpercpasswpc12'}     & \mcc{`sysGMMhansenpercpasswpc11'}    & \mcc{`sysGMMhansenpercpass21'}    & \mcc{`sysGMMhansenpercpasswpc23'}    & \mcc{`sysGMMhansenpercpasswpc22'}     & \mcc{`sysGMMhansenpercpasswpc21'} \\
tex Med.\ cond.\ F                    & \mcc{`sysGMMcondFDFI1med1'}       & \mcc{`sysGMMcondFDFIwpc1med3'}       & \mcc{`sysGMMcondFDFIwpc1med2'}        & \mcc{`sysGMMcondFDFIwpc1med1'}       & \mcc{`sysGMMcondFDFI2med1'}       & \mcc{`sysGMMcondFDFIwpc2med3'}       & \mcc{`sysGMMcondFDFIwpc2med2'}        & \mcc{`sysGMMcondFDFIwpc2med1'} \\
tex \mbox{\% reject underid.}         & \mcc{`sysGMMcondFDFIpercrej11'}   & \mcc{`sysGMMcondFDFIpercrejwpc13'}   & \mcc{`sysGMMcondFDFIpercrejwpc12'}    & \mcc{`sysGMMcondFDFIpercrejwpc11'}   & \mcc{`sysGMMcondFDFIpercrej21'}   & \mcc{`sysGMMcondFDFIpercrejwpc23'}   & \mcc{`sysGMMcondFDFIpercrejwpc22'}    & \mcc{`sysGMMcondFDFIpercrejwpc21'} \\
tex \bottomrule
texdoc close


/* Additional experiments. */
texdoc init "`tablesexport'/GMMexport_zeroadd_2_capped.tex", replace force
tex  								  & \mcolsfe{(1)} 				      & \mcolsfe{(2)} 				                                    & \mcolsfe{(3)} 				    & \mcolsfe{(4)} 					                           & \mcolsfe{(5)} 				       & \mcolsfe{(6)} 				                           & \mcolsfe{(7)} 						 & \mcolsfe{(8)} \\
tex Experiment description            & \multicolumn{2}{c}{\begin{tabular}{@{}c@{}}Upward trend \tabularnewline in DFI budget\end{tabular}} & \multicolumn{2}{c}{\begin{tabular}{@{}c@{}}$\mu_c$ closer \tabularnewline together\end{tabular}} & \multicolumn{2}{c}{\begin{tabular}{@{}c@{}}$\mu_c$ the \tabularnewline same\end{tabular}} &  \multicolumn{2}{c}{\begin{tabular}{@{}c@{}}Upward trend \tabularnewline in DFI budget, \tabularnewline fixed types\end{tabular}} \\
tex $\mathit{pc}$                     & \mcolsfe{excl.}                   & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}}                           & \mcolsfe{excl.}                   & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}}                        & \mcolsfe{excl.}                   & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}}                 & \mcolsfe{excl.}                     & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}} \\
tex $\sigma_{db}$                     & \mcc{0}                           & \mcc{0}                                                         & \mcc{0.15}                        & \mcc{0.15}                                                   & \mcc{0.15}                        & \mcc{0.15}                                            & \mcc{0}                             & \mcc{0} \\
tex $\mathit{drift}$                  & \mcc{0.05}                        & \mcc{0.05}                                                      & \mcc{0}                           & \mcc{0}                                                      & \mcc{0}                           & \mcc{0}                                               & \mcc{0.05}                          & \mcc{0.05} \\
tex $\mu_c$                           & \mcc{$\left[0, 2, 4\right]$}      & \mcc{$\left[0, 2, 4\right]$}                                    & \mcc{$\left[1, 2, 3\right]$}      & \mcc{$\left[1, 2, 3\right]$}                                 & \mcc{$\left[2, 2, 2\right]$}      & \mcc{$\left[2, 2, 2\right]$}                          & \mcc{$\left[0, 2, 4\right]$}        & \mcc{$\left[0, 2, 4\right]$} \\
tex $\Delta$ types                    & \mcolsfe{default}                 & \mcolsfe{default}                                               & \mcolsfe{default}                 & \mcolsfe{default}                                            & \mcolsfe{default}                 & \mcolsfe{default}                                     & \mcolsfe{fixed}                     & \mcolsfe{fixed} \\
tex \cmidrule{1-9}                                                                  
tex Med.\ $\widehat{\beta}_{sysGMM}$  & NA								  & NA									                            & `sysGMM1betadfimedian4'           & `sysGMMwpc1betadfimedian4'                                   & `sysGMM1betadfimedian5'           & `sysGMMwpc1betadfimedian5'                            & NA								     & NA 		\\
tex Std.\ dev.\	                      & NA								  & NA									                            & `sysGMM1betadfisd4'               & `sysGMMwpc1betadfisd4'                                       & `sysGMM1betadfisd5'               & `sysGMMwpc1betadfisd5'                                & NA								     & NA 		\\
tex \% reject $\beta \leqslant 0$     & NA								  & NA									                            & \mcc{`sysGMMzeroaddpercreject14'} & \mcc{`sysGMMzeroaddpercrejectwpc14'}                         & \mcc{`sysGMMzeroaddpercreject15'} & \mcc{`sysGMMzeroaddpercrejectwpc15'}                  & NA								     & NA 		\\
tex Hansen \% pass                    & NA								  & NA									                            & \mcc{`sysGMMhansenpercpass14'}    & \mcc{`sysGMMhansenpercpasswpc14'}                            & \mcc{`sysGMMhansenpercpass15'}    & \mcc{`sysGMMhansenpercpasswpc15'}                     & NA								     & NA 		\\
tex Med.\ cond.\ F                    & NA								  & NA									                            & \mcc{`sysGMMcondFDFI1med4'}       & \mcc{`sysGMMcondFDFIwpc1med4'}                               & \mcc{`sysGMMcondFDFI1med5'}       & \mcc{`sysGMMcondFDFIwpc1med5'}                        & NA								     & NA 		\\
tex \mbox{\% reject underid.}         & NA								  & NA									                            & \mcc{`sysGMMcondFDFIpercrej14'}   & \mcc{`sysGMMcondFDFIpercrejwpc14'}                           & \mcc{`sysGMMcondFDFIpercrej15'}   & \mcc{`sysGMMcondFDFIpercrejwpc15'}                    & NA								     & NA 		\\
tex Med.\ $\widehat{\beta}_{diffGMM}$ & NA								  & NA									                            & `sysGMM5betadfimedian4'           & `sysGMMwpc5betadfimedian4'                                   & `sysGMM5betadfimedian5'           & `sysGMMwpc5betadfimedian5'                            & NA								     & NA 		\\
tex Med.\ $\widehat{\beta}_{levGMM}$  & NA								  & NA									                            & `sysGMM7betadfimedian4'           & `sysGMMwpc7betadfimedian4'                                   & `sysGMM7betadfimedian5'           & `sysGMMwpc7betadfimedian5'                            & NA								     & NA 		\\
tex \bottomrule
texdoc close


*************************************************************************
* SUPPLY-PUSH IV WITH ZERO ADDITIONALITY
*************************************************************************
foreach num of numlist 1/8 {
	clear
	capture log close
	log using "./Generated data/IVzeroaddcapped`num'", replace text
	use "./Generated data/IVzeroaddcapped`num'.dta"


	/* First check if all replications have been successful. */
	egen nummissing = rowmiss(ivbetadfi-type3dfiinvIVy20)
	tab nummissing, missing
	count if nummissing == 0
	scalar successfulreps = r(N)
	foreach var of varlist * { 
		replace `var' = . if nummissing != 0
	}

		
	/* Now pick up selected IV statistics to export to Excel later: */
	su ivbetadfi, detail
	scalar IVbetadfimean=r(mean)
	scalar IVbetadfimedian=r(p50)
	local IVbetadfimedian`num': di %4.2f IVbetadfimedian				
	scalar IVbetadfisd=r(sd)
	local IVbetadfisd`num': di %4.2f IVbetadfisd							
	su febetadfi, detail
	scalar FEbetadfimean=r(mean)
	scalar FEbetadfimedian=r(p50)
	su ivbetadfil1out, detail
	scalar IVbetadfil1outmedian=r(p50)
	local IVbetadfimedianl1out`num': di %4.2f IVbetadfil1outmedian				
	scalar IVbetadfil1outsd=r(sd)
	local IVbetadfil1outsd`num': di %4.2f IVbetadfil1outsd							
	su ivbetadfict, detail
	scalar IVbetadfictmedian=r(p50)
	local IVbetadfictmedian`num': di %4.2f IVbetadfictmedian				
	scalar IVbetadfictsd=r(sd)
	local IVbetadfictsd`num': di %4.2f IVbetadfictsd							
	//
	su ivpcbetadfi, detail
	scalar IVpcbetadfimean=r(mean)
	scalar IVpcbetadfimedian=r(p50)
	local IVpcbetadfimedian`num': di %4.2f IVpcbetadfimedian				
	scalar IVpcbetadfisd=r(sd)
	local IVpcbetadfisd`num': di %4.2f IVpcbetadfisd						
	su fepcbetadfi, detail
	scalar FEpcbetadfimean=r(mean)
	scalar FEpcbetadfimedian=r(p50)
	su ivpcbetadfil1out, detail
	scalar IVpcbetadfil1outmedian=r(p50)
	//		
	count if ivpzeroadd < 0.05
	scalar IVzeroaddpercreject=(r(N)/successfulreps)*100
	local IVzeroaddpercreject`num': di %5.0g IVzeroaddpercreject
	count if ivpzeroaddl1out < 0.05
	scalar IVzeroaddpercrejectl1out=(r(N)/successfulreps)*100
	local IVzeroaddpercrejectl1out`num': di %5.0g IVzeroaddpercrejectl1out
	count if ivpzeroaddct < 0.05
	scalar IVzeroaddpercrejectct=(r(N)/successfulreps)*100
	local IVzeroaddpercrejectct`num': di %5.0g IVzeroaddpercrejectct
	//
	count if ivpcpzeroadd < 0.05
	scalar IVpczeroaddpercreject=(r(N)/successfulreps)*100
	local IVpczeroaddpercreject`num': di %5.0g IVpczeroaddpercreject
	count if ivpcpzeroaddl1out < 0.05
	scalar IVpczeroaddpercrejectl1out=(r(N)/successfulreps)*100
	//
	su weakid, detail
	scalar IVmedFSF=r(p50)
	local IVmedFSF`num': di %5.0g IVmedFSF
	scalar IVminFSF=r(min)
	count if weakid > 10 & weakid != .
	scalar IVFSFpercover10=(r(N)/successfulreps)*100
	su weakidl1out, detail
	scalar IVmedFSFl1out=r(p50)
	local IVmedFSFl1out`num': di %5.0g IVmedFSFl1out
	su weakidct, detail
	scalar IVmedFSFct=r(p50)
	local IVmedFSFct`num': di %5.0g IVmedFSFct
	su underid, detail
	scalar IVmedFSLM=r(p50)
	scalar IVminFSLM=r(min)
	count if underid > 10 & underid != .
	scalar IVFSLMpercover10=(r(N)/successfulreps)*100
	su underidl1out, detail
	scalar IVmedFSLMl1out=r(p50)
	su underidct, detail
	scalar IVmedFSLMct=r(p50)
	count if underidp < 0.05
	scalar IVunderidpercreject=(r(N)/successfulreps)*100
	local IVunderidpercreject`num': di %5.0g IVunderidpercreject
	count if underidpl1out < 0.05
	scalar IVunderidpercrejectl1out=(r(N)/successfulreps)*100	
	local IVunderidpercrejectl1out`num': di %5.0g IVunderidpercrejectl1out
	count if underidpct < 0.05
	scalar IVunderidpercrejectct=(r(N)/successfulreps)*100	
	local IVunderidpercrejectct`num': di %5.0g IVunderidpercrejectct
	//
	su weakidpc, detail
	scalar IVpcmedFSF=r(p50)
	local IVpcmedFSF`num': di %5.0g IVpcmedFSF
	scalar IVpcminFSF=r(min)
	count if weakidpc > 10 & weakidpc != .
	scalar IVpcFSFpercover10=(r(N)/successfulreps)*100
	su weakidpcl1out, detail
	scalar IVpcmedFSFl1out=r(p50)
	su underidpc, detail
	scalar IVpcmedFSLM=r(p50)
	scalar IVpcminFSLM=r(min)
	count if underidpc > 10 & underidpc != .
	scalar IVpcFSLMpercover10=(r(N)/successfulreps)*100
	su underidpcl1out, detail
	scalar IVpcmedFSLMl1out=r(p50)
	count if underidppc < 0.05
	scalar IVpcunderidpercreject=(r(N)/successfulreps)*100
	local IVpcunderidpercreject`num': di %5.0g IVpcunderidpercreject
	count if underidppcl1out < 0.05
	scalar IVpcunderidpercrejectl1out=(r(N)/successfulreps)*100	
	//
	su ivFSbeta, detail
	scalar IVbetaFSmean=r(mean)
	scalar IVbetaFSmedian=r(p50)
	scalar IVbetaFSsd=r(sd)
	local IVbetaFSmedian`num': di %4.2f IVbetaFSmedian				
	su ivRFbeta, detail
	scalar IVbetaRFmean=r(mean)
	scalar IVbetaRFmedian=r(p50)
	scalar IVbetaRFsd=r(sd)
	local IVbetaRFmedian`num': di %4.2f IVbetaRFmedian				
	su ivFSbetact, detail
	scalar IVbetactFSmean=r(mean)
	scalar IVbetactFSmedian=r(p50)
	scalar IVbetactFSsd=r(sd)
	local IVbetactFSmedian`num': di %4.2f IVbetactFSmedian				
	su ivRFbetact, detail
	scalar IVbetactRFmean=r(mean)
	scalar IVbetactRFmedian=r(p50)
	scalar IVbetactRFsd=r(sd)
	local IVbetactRFmedian`num': di %4.2f IVbetactRFmedian				
	//
	su ivpcFSbeta, detail
	scalar IVpcbetaFSmean=r(mean)
	scalar IVpcbetaFSmedian=r(p50)
	scalar IVpcbetaFSsd=r(sd)
	local IVpcbetaFSmedian`num': di %4.2f IVpcbetaFSmedian				
	su ivpcRFbeta, detail
	scalar IVpcbetaRFmean=r(mean)
	scalar IVpcbetaRFmedian=r(p50)
	scalar IVpcbetaRFsd=r(sd)
	local IVpcbetaRFmedian`num': di %4.2f IVpcbetaRFmedian				

	
	/* Bias in IV */
	su ivbetadfitrue, detail
	scalar IVbetadfitruemean = r(mean)
	su ivbetanumprojerover2, detail
	scalar IVbetanumprojerover2mean = r(mean)
	// with pc
	su ivpcbetadfitrue, detail
	scalar IVpcbetadfitruemean = r(mean)
	su ivpcbetanumprojerover2, detail
	scalar IVpcbetanumprojerover2mean = r(mean)
	su ivpcbetapctrue, detail
	scalar IVpcbetapctruemean = r(mean)
	//
	gen double bias = covzu/covzx
	su bias, detail
	scalar IVbiasdfimean = r(mean)
	scalar IVbiasdfimedian = r(p50)
	gen double bias2 = (corrzu/corrzx)*(sdu/sdx)
	su bias2, detail 
	scalar IVbias2dfimean = r(mean)
	scalar IVbias2dfimedian = r(p50)
	su covzu, detail
	scalar IVcovzumean = r(mean)
	scalar IVcovzumedian = r(p50)
	su covzx, detail
	scalar IVcovzxmean = r(mean)
	scalar IVcovzxmedian = r(p50)
	su varz, detail
	scalar IVvarzmean = r(mean)
	scalar IVvarzmedian = r(p50)
	su corrzu, detail
	scalar IVcorrzumean = r(mean)
	scalar IVcorrzumedian = r(p50)
	su corrzx, detail
	scalar IVcorrzxmean = r(mean)
	scalar IVcorrzxmedian = r(p50)
	su sdu, detail
	scalar IVsdumean = r(mean)
	scalar IVsdumedian = r(p50)
	su sdx, detail
	scalar IVsdxmean = r(mean)
	scalar IVsdxmedian = r(p50)
	//
	gen double pcbias = pccovzu/pccovzx
	su pcbias, detail
	scalar IVpcbiasdfimean = r(mean)
	scalar IVpcbiasdfimedian = r(p50)
	gen double pcbias2 = (pccorrzu/pccorrzx)*(pcsdu/pcsdx)
	su pcbias2, detail
	scalar IVpcbias2dfimean = r(mean)
	scalar IVpcbias2dfimedian = r(p50)
	su pccovzu, detail
	scalar IVpccovzumean = r(mean)
	scalar IVpccovzumedian = r(p50)
	su pccovzx, detail
	scalar IVpccovzxmean = r(mean)
	scalar IVpccovzxmedian = r(p50)
	su pcvarz, detail
	scalar IVpcvarzmean = r(mean)
	scalar IVpcvarzmedian = r(p50)
	su pccorrzu, detail
	scalar IVpccorrzumean = r(mean)
	scalar IVpccorrzumedian = r(p50)
	su pccorrzx, detail
	scalar IVpccorrzxmean = r(mean)
	scalar IVpccorrzxmedian = r(p50)
	su pcsdu, detail
	scalar IVpcsdumean = r(mean)
	scalar IVpcsdumedian = r(p50)
	su pcsdx, detail
	scalar IVpcsdxmean = r(mean)
	scalar IVpcsdxmedian = r(p50)
	
	
	/* Evolution of variables by type */
	foreach var of varlist type1invy1-type3dfiinvIVy20 {
		su `var', detail
		scalar `var'med = r(p50)
	}

	
	count if maxdbpercnumprojerover2 >= 1 & maxdbpercnumprojerover2 != .
	scalar countmaxdbpercnumprojerover2exc1 = r(N)

	su medinvDFIvsprivate, detail
	scalar medmedinvDFIvsprivate = r(p50)
			
	scalar empty = .
	scalar number = `num'

	
	// Put statistics in matrix:
	matrix IVzeroadd_`num' = (number \ IVbetadfimean \ IVbetadfimedian \ IVbetadfisd \ IVzeroaddpercreject /// 
	\ IVmedFSF \ IVminFSF \ IVFSFpercover10 \ IVmedFSLM \ IVminFSLM \ IVFSLMpercover10 \ IVunderidpercreject ///
	\ IVbetaFSmean \ IVbetaFSmedian \ IVbetaFSsd \ IVbetaRFmean \ IVbetaRFmedian \ IVbetaRFsd \ FEbetadfimean \ FEbetadfimedian ///
	\ IVbetadfil1outmedian \ IVzeroaddpercrejectl1out /// 
	\ IVmedFSFl1out \ IVmedFSLMl1out \ IVunderidpercrejectl1out ///
	\ IVbetadfictmedian \ IVzeroaddpercrejectct /// 
	\ IVmedFSFct \ IVmedFSLMct \ IVunderidpercrejectct ///
	\ IVbetactFSmean \ IVbetactFSmedian \ IVbetactFSsd \ IVbetactRFmean \ IVbetactRFmedian \ IVbetactRFsd ///
	\ IVbetadfitruemean \ IVbetanumprojerover2mean \ IVbiasdfimean \ IVcovzumean \ IVcovzxmean \ IVvarzmean \ IVbias2dfimean \ IVcorrzumean \ IVcorrzxmean \ IVsdumean \ IVsdxmean ///
	\ IVbiasdfimedian \ IVcovzumedian \ IVcovzxmedian \ IVvarzmedian \ IVbias2dfimedian \ IVcorrzumedian \ IVcorrzxmedian \ IVsdumedian \ IVsdxmedian \ empty ///
	\ type1invy1med \ type1invy20med \ type2invy1med \ type2invy20med \ type3invy1med \ type3invy20med ///
	\ type1dfiinvy1med \ type1dfiinvy20med \ type2dfiinvy1med \ type2dfiinvy20med \ type3dfiinvy1med \ type3dfiinvy20med ///
	\ type1dfiinvIVy1med \ type1dfiinvIVy20med \ type2dfiinvIVy1med \ type2dfiinvIVy20med \ type3dfiinvIVy1med \ type3dfiinvIVy20med \ empty /// 
	\ IVpcbetadfimean \ IVpcbetadfimedian \ IVpcbetadfisd \ IVpczeroaddpercreject ///
	\ IVpcmedFSF \ IVpcminFSF \ IVpcFSFpercover10 \ IVpcmedFSLM \ IVpcminFSLM \ IVpcFSLMpercover10 \ IVpcunderidpercreject /// 
	\ IVpcbetaFSmean \ IVpcbetaFSmedian \ IVpcbetaFSsd \ IVpcbetaRFmean \ IVpcbetaRFmedian \ IVpcbetaRFsd \ FEpcbetadfimean \ FEpcbetadfimedian ///
	\ IVpcbetadfil1outmedian \ IVpczeroaddpercrejectl1out ///
	\ IVpcmedFSFl1out \ IVpcmedFSLMl1out \ IVpcunderidpercrejectl1out ///
	\ IVpcbetadfitruemean \ IVpcbetanumprojerover2mean \ IVpcbetapctruemean \ IVpcbiasdfimean \ IVpccovzumean \ IVpccovzxmean \ IVpcvarzmean /// 
	\ IVpcbias2dfimean \ IVpccorrzumean \ IVpccorrzxmean \ IVpcsdumean \ IVpcsdxmean /// 
	\ IVpcbiasdfimedian \ IVpccovzumedian \ IVpccovzxmedian \ IVpcvarzmedian \ IVpcbias2dfimedian /// 
	\ IVpccorrzumedian \ IVpccorrzxmedian \ IVpcsdumedian \ IVpcsdxmedian /// 
	\ empty \ countmaxdbpercnumprojerover2exc1 \ successfulreps \ medmedinvDFIvsprivate)
	matrix list IVzeroadd_`num'
	log close
}


/* Construct matrices that combine results. */
foreach num of numlist 1/8 {
	if `num'==1 { 
		matrix tableIVzeroadd = IVzeroadd_`num'
	}
	else { 
		matrix tableIVzeroadd=(tableIVzeroadd, IVzeroadd_`num')
	}        
}

 
/* Export to Excel and clean up tables. */
putexcel set "./Tables/IVzeroaddtable_capped", replace
putexcel C2 = matrix(tableIVzeroadd) // starting point of table
//
putexcel A3 = "Without pc"
putexcel A20 = "FE (no IV)"
putexcel A22 = "Leave 1 out"
putexcel A27 = "Country trend"
putexcel A38 = "Analyse bias"
putexcel A59 = "Evolution of types"
putexcel A78 = "With pc"
putexcel A95 = "FE (no IV)"
putexcel A97 = "Leave 1 out"
putexcel A103 = "Analyse bias"
//
local row 3
putexcel B`row++' = "DFI coeff. mean"
putexcel B`row++' = "DFI coeff. median"
putexcel B`row++' = "DFI coeff. st. dev."
putexcel B`row++' = "% reject zero additionality"
putexcel B`row++' = "Median FS F"
putexcel B`row++' = "Min. FS F"
putexcel B`row++' = "% FS F > 10"
putexcel B`row++' = "Median FS LM"
putexcel B`row++' = "Min. FS LM"
putexcel B`row++' = "% FS LM > 10"
putexcel B`row++' = "% reject underidentification"
putexcel B`row++' = "FS instr. coeff. mean"
putexcel B`row++' = "FS instr. coeff. median"
putexcel B`row++' = "FS instr. coeff. st. dev."
putexcel B`row++' = "RF instr. coeff. mean"
putexcel B`row++' = "RF instr. coeff. median"
putexcel B`row++' = "RF instr. coeff. st. dev."
putexcel B`row++' = "FE DFI coeff. mean"
putexcel B`row++' = "FE DFI coeff. median"
putexcel B`row++' = "DFI coeff. median leave 1 out"
putexcel B`row++' = "% reject zero add. leave 1 out"
putexcel B`row++' = "Median FS F leave 1 out"
putexcel B`row++' = "Median FS LM leave 1 out"
putexcel B`row++' = "% reject underid. leave 1 out"
putexcel B`row++' = "DFI coeff. median country trend"
putexcel B`row++' = "% reject zero add. country trend"
putexcel B`row++' = "Median FS F country trend"
putexcel B`row++' = "Median FS LM country trend"
putexcel B`row++' = "% reject underid. country trend"
putexcel B`row++' = "FS instr. coeff. mean"
putexcel B`row++' = "FS instr. coeff. median"
putexcel B`row++' = "FS instr. coeff. st. dev."
putexcel B`row++' = "RF instr. coeff. mean"
putexcel B`row++' = "RF instr. coeff. median"
putexcel B`row++' = "RF instr. coeff. st. dev."
putexcel B`row++' = "DFI coeff. mean in true model"
putexcel B`row++' = "# projects er > 2 coeff. mean"
putexcel B`row++' = "DFI coeff. bias mean"
putexcel B`row++' = "Cov(z,u) mean"
putexcel B`row++' = "Cov(z,x) mean"
putexcel B`row++' = "Var(z) mean"
putexcel B`row++' = "DFI coeff. bias mean"
putexcel B`row++' = "Corr(z,u) mean"
putexcel B`row++' = "Corr(z,x) mean"
putexcel B`row++' = "Sd(u) mean"
putexcel B`row++' = "Sd(x) mean"
putexcel B`row++' = "DFI coeff. bias median"
putexcel B`row++' = "Cov(z,u) median"
putexcel B`row++' = "Cov(z,x) median"
putexcel B`row++' = "Var(z) median"
putexcel B`row++' = "DFI coeff. bias median"
putexcel B`row++' = "Corr(z,u) median"
putexcel B`row++' = "Corr(z,x) median"
putexcel B`row++' = "Sd(u) median"
putexcel B`row++' = "Sd(x) median"
putexcel B`row++' = " "
putexcel B`row++' = "Type 1 median inv Y1"
putexcel B`row++' = "Type 1 median inv Y20"
putexcel B`row++' = "Type 2 median inv Y1"
putexcel B`row++' = "Type 2 median inv Y20"
putexcel B`row++' = "Type 3 median inv Y1"
putexcel B`row++' = "Type 3 median inv Y20"
putexcel B`row++' = "Type 1 median DFI inv Y1"
putexcel B`row++' = "Type 1 median DFI inv Y20"
putexcel B`row++' = "Type 2 median DFI inv Y1"
putexcel B`row++' = "Type 2 median DFI inv Y20"
putexcel B`row++' = "Type 3 median DFI inv Y1"
putexcel B`row++' = "Type 3 median DFI inv Y20"
putexcel B`row++' = "Type 1 median DFI inv IV Y1"
putexcel B`row++' = "Type 1 median DFI inv IV Y20"
putexcel B`row++' = "Type 2 median DFI inv IV Y1"
putexcel B`row++' = "Type 2 median DFI inv IV Y20"
putexcel B`row++' = "Type 3 median DFI inv IV Y1"
putexcel B`row++' = "Type 3 median DFI inv IV Y20"
//
putexcel B`row++' = " "
putexcel B`row++' = "DFI coeff. mean"
putexcel B`row++' = "DFI coeff. median"
putexcel B`row++' = "DFI coeff. st. dev."
putexcel B`row++' = "% reject zero additionality"
putexcel B`row++' = "Median FS F"
putexcel B`row++' = "Min. FS F"
putexcel B`row++' = "% FS F > 10"
putexcel B`row++' = "Median FS LM"
putexcel B`row++' = "Min. FS LM"
putexcel B`row++' = "% FS LM > 10"
putexcel B`row++' = "% reject underidentification"
putexcel B`row++' = "FS instr. coeff. mean"
putexcel B`row++' = "FS instr. coeff. median"
putexcel B`row++' = "FS instr. coeff. st. dev."
putexcel B`row++' = "RF instr. coeff. mean"
putexcel B`row++' = "RF instr. coeff. median"
putexcel B`row++' = "RF instr. coeff. st. dev."
putexcel B`row++' = "FE DFI coeff. mean"
putexcel B`row++' = "FE DFI coeff. median"
putexcel B`row++' = "DFI coeff. median leave 1 out"
putexcel B`row++' = "% reject zero add. leave 1 out"
putexcel B`row++' = "Median FS F leave 1 out"
putexcel B`row++' = "Median FS LM leave 1 out"
putexcel B`row++' = "% reject underid. leave 1 out"
putexcel B`row++' = "DFI coeff. mean in true model"
putexcel B`row++' = "# projects er > 2 coeff. mean"
putexcel B`row++' = "pc coeff. mean in true model"
putexcel B`row++' = "DFI coeff. bias mean"
putexcel B`row++' = "Cov(z,u) mean"
putexcel B`row++' = "Cov(z,x) mean"
putexcel B`row++' = "Var(z) mean"
putexcel B`row++' = "DFI coeff. bias mean"
putexcel B`row++' = "Corr(z,u) mean"
putexcel B`row++' = "Corr(z,x) mean"
putexcel B`row++' = "Sd(u) mean"
putexcel B`row++' = "Sd(x) mean"
putexcel B`row++' = "DFI coeff. bias median"
putexcel B`row++' = "Cov(z,u) median"
putexcel B`row++' = "Cov(z,x) median"
putexcel B`row++' = "Var(z) median"
putexcel B`row++' = "DFI coeff. bias median"
putexcel B`row++' = "Corr(z,u) median"
putexcel B`row++' = "Corr(z,x) median"
putexcel B`row++' = "Sd(u) median"
putexcel B`row++' = "Sd(x) median"
//
putexcel B`row++' = " "
putexcel B`row++' = "Number of datasets where max db exceeds # proj. er > 2"
putexcel B`row++' = "# successful replications"
putexcel B`row++' = "Med. of med. DFI inv/private"
//
putexcel C1= "default, pc noise 0.5"
putexcel D1= "fewertrans, pc noise 0.5"
putexcel E1= "oneperiodchange, pc noise 0.5"
putexcel F1= "fixedtypes, pc noise 0.5"
putexcel G1= "oneperiodchange, pc noise 0.5, phi = 1"
putexcel H1= "oneperiodchange, pc noise 0.5, phi = 2"
putexcel I1= "oneperiodchange, pc noise 0.5, phi = 2, sigma = 0.05"
putexcel J1= "oneperiodchange, pc noise 1, phi = 2, sigma = 0.05"


/* Now generate tables to export to TeX, using texdoc. */
texdoc init "`tablesexport'/IVexport_zeroadd_capped.tex", replace force
tex  								  & \mcolsfe{(1)} 				      & \mcolsfe{(2)} 				         & \mcolsfe{(3)} 				         & \mcolsfe{(4)} 					    & \mcolsfe{(5)} 				    & \mcolsfe{(6)} 				       & \mcolsfe{(7)} 						   & \mcolsfe{(8)} \\
tex $\Delta$ types                    & \mcolsfe{default}                 & \mcolsfe{fewer}                      & \mcolsfe{1period}                     & \mcolsfe{fixed}                      & \mcolsfe{1period}                 & \mcolsfe{1period}                    & \mcolsfe{1period}                     & \mcolsfe{1period}  \\
tex $\phi$                            & \mcc{0}                           & \mcc{0}                              & \mcc{0}                               & \mcc{0}                              & \mcc{1}                           & \mcc{2}                              & \mcc{2}                               & \mcc{1}                      \\
tex $\mathit{pc}$                     & \mcolsfe{excl.}                   & \mcolsfe{excl.}                      & \mcolsfe{excl.}                       & \mcolsfe{excl.}                      & \mcolsfe{excl.}                   & \mcolsfe{excl.}                      & \mcolsfe{\mbox{$\sigma_m^{2} = 0.5$}} & \mcolsfe{excl.} \\
tex $\sigma_{db}$                     & \mcc{0.15}                        & \mcc{0.15}                           & \mcc{0.15}                            & \mcc{0.15}                           & \mcc{0.15}                        & \mcc{0.15}                           & \mcc{0.05}                            & \mcc{0.15}                   \\
tex Instrument                     	  & \mcolsfe{standard}                & \mcolsfe{standard}                   & \mcolsfe{standard}                    & \mcolsfe{standard}                   & \mcolsfe{standard}                & \mcolsfe{standard}                   & \mcolsfe{standard}                    & \mcolsfe{leave1out}                   \\
tex \cmidrule{1-9}
tex Med.\ $\widehat{\beta}_{IV}$      & `IVbetadfimedian1'                & `IVbetadfimedian2'                   & `IVbetadfimedian3'                    & `IVbetadfimedian4'                   & `IVbetadfimedian5'                & `IVbetadfimedian6'                   & `IVpcbetadfimedian7'                  & `IVbetadfimedianl1out5'   \\
tex Std.\ dev.\	                      & \mcc{`IVbetadfisd1'}              & \mcc{`IVbetadfisd2'}                 & \mcc{`IVbetadfisd3'}                  & \mcc{`IVbetadfisd4'}                 & \mcc{`IVbetadfisd5'}              & \mcc{`IVbetadfisd6'}                 & \mcc{`IVpcbetadfisd7'}                & \mcc{`IVbetadfil1outsd5'}   \\
tex \% reject $\beta \leqslant 0$     & \mcc{`IVzeroaddpercreject1'}      & \mcc{`IVzeroaddpercreject2'}         & \mcc{`IVzeroaddpercreject3'}          & \mcc{`IVzeroaddpercreject4'}         & \mcc{`IVzeroaddpercreject5'}      & \mcc{`IVzeroaddpercreject6'}         & \mcc{`IVpczeroaddpercreject7'}        & \mcc{`IVzeroaddpercrejectl1out5'} \\
tex Med.\ F                           & \mcc{`IVmedFSF1'}                 & \mcc{`IVmedFSF2'}                    & \mcc{`IVmedFSF3'}                     & \mcc{`IVmedFSF4'}                    & \mcc{`IVmedFSF5'}                 & \mcc{`IVmedFSF6'}                    & \mcc{`IVpcmedFSF7'}                   & \mcc{`IVmedFSFl1out5'} \\
tex \mbox{\% reject underid.}         & \mcc{`IVunderidpercreject1'}      & \mcc{`IVunderidpercreject2'}         & \mcc{`IVunderidpercreject3'}          & \mcc{`IVunderidpercreject4'}         & \mcc{`IVunderidpercreject5'}      & \mcc{`IVunderidpercreject6'}         & \mcc{`IVpcunderidpercreject7'}        & \mcc{`IVunderidpercrejectl1out5'} \\
tex \bottomrule
texdoc close


